use strict; use warnings; use CGI qw(:standard); use CGI::Cookie; my %cookie = CGI::Cookie->fetch; if (exists $cookie{test}) { print header, start_html('got cookie'), p('found the cookie: ' . $cookie{test}->value), end_html, ; } else { my $cookie = CGI::Cookie->new(-name=>'test',-value=>12345); print header(-cookie=>$cookie), start_html('need cookie'), p('setting cookie, please reload'), end_html, ; }