use CGI; my $q = new CGI; my $cookie = $q->cookie(-name=>'form_info') || ''; if ($cookie) { # you have the cookie, validate the info or whatever now } elsif ($q->param('form_info')) { # you've received the form info # now set the cookie my $cookie_to_send = $q->cookie(-name=>'form_info'); # print out header print $q->header(-cookie=>$cookie); # print out HTML header, then html document } else { # no cookie or form params received # print out HTML form }