Listing 1:, Program to Create a Cookie

#!/usr/bin/perl -w
use strict;
use diagnostics;
use CGI;

# Create an instance of CGI
my $query = new CGI;

# Create a new cookie with a name "counter" and
# the value "1".
my $cookie = $query->cookie(-name => "counter",
   -value => 1);

# Send a header to the user, including a cookie
print $query->header(-type => "text/html",
   -cookie => $cookie);

# Send some HTML as a placeholder
print $query->start_html(-title => "Cookie set");
print "<P>The counter cookie is set to 1.</P>\n";
print $query->end_html;