use CGI qw(:cgi); # Name of this script, for example my $script = script_name(); my $query = get_param('action') || 'start';' my %actions = ( start => \&do_start, login => \&do_login ); &{ $actions{$query} } sub do_start { my $cookie = cookie('cookie_name'), # Check $cookie value, note that cookies # aren't to be trusted 100% if($cookie) { showsecretcontent(); } else { show_loginpage(); } } sub showsecretcontent { # prints secret content page } sub show_loginpage { # prints login page # Have a hidden field and set its name as 'action' # and its value to 'login' } sub do_login { # process results do_refresh(); } sub do_refresh { my $cookie = ( -name => 'mycookie', -value => 'youareloggedin', -path=>'/', -expires => '+1y' ); print header (-cookie => $cookie); start_html(); print qq~~; print p("You've successfully logged in. Please wait while you're re-direced..."); end_html(); }