$exit_link = "$ENV{'QUERY_STRING'}"; $cookie = $query->cookie(-name=>'aa_exit', -value=>$exit_link, -expires=>'+4h', -path=>'/'); ... $theCookie = $query->cookie('aa_exit'); if(!$theCookie){ $exit_link = "$ENV{'QUERY_STRING'}"; # $theCookie = $query->cookie('aa_exit'); WRONG $theCookie = $ENV{'QUERY_STRING'}; ... }