The CGI module is the backbone of most Perl Web applications. It exposes both procedural and object-oriented interfaces to the basic requirements of any Web application, including access to form variables, creating standard HTTP headers, as well as dynamically generating HTML.
Regular expressions are built into the Perl language. Instead of calling functions, you invoke regular expressions using special operators with sed-like syntax.
use CGI; # Instantiate a new CGI object my $query = new CGI; # Print the HTTP header print $query->header(); # Print our HTML header and search form print header('Search for a menu item'); # Declare the $search variable in the global scope my $search; # Ensure the requested CGI parameter actually exists if ($query->param('search')) { # Whitelist filter the input string to prevent naughty input ($search) = $query->param('search') =~ m/^([^\W_]+)$/; } if (!$search) { print "Please enter an alphanumeric search string."; exit; } sub header { my ($title) = @_; my $header = "<html> <head><title>$title</title></head> <body><h1>$title</h1>"; $header .= q{ <form action='search.pl' method='POST'> <label for='sinput'>Please enter the search string:</label> <input type='text' name='search' id='sinput' size='30'/><br /> <input type='submit'/><input type='reset'/> </form> }; return $header; }