use CGI ':standard'; my @cookies = (); push @cookies, cookie() if $test; # etc... test2() ? redirect($url) : header(-cookie => \@cookies); # go on to create the page.