# (mostly) From the tutorial link above- use strict; # Important! use warnings; # Ditto! my $session = CGI::Session->new() or die CGI::Session->errstr; Above line will first try to re-initialize an existing session by consulting cookies and necessary QUERY_STRING parameters. If it fails will create a brand new session with a unique ID, which is normally called session ID, SID for short, and can be accessed through id() - object method. We didn't check for any session cookies above, did we? No, we didn't, but CGI::Session did. It looked for a cookie called CGISESSID, and if it found it tried to load existing session from server side storage (file in our case). If cookie didn't exist it looked for a QUERY_STRING parameter called CGISESSID. If all the attempts to recover session ID failed, it created a new session. #### use strict; use warnings; use CGI::Session; use CGI qw( h1 p ); use CGI::Carp "fatalsToBrowser"; my $session = CGI::Session->new or die CGI::Session->errstr; print $session->header(); if ( $session->param("visits") ) { print h1("Welcome back!"); print p( sprintf("You've been here %d time%s.", $session->param("visits"), $session->param("visits") == 1 ? "" : "s", ) ); } else { print h1("Welcome first time visitor"); } $session->param( visits => $session->param("visits") + 1 );