use warnings; no warnings 'uninitialized'; use strict; use CGI qw(:standard); use DBI; my $data_source = 'whatever'; my $username = 'whoever'; my $auth = 'whichever'; my %attr = (); print header(), start_html(-title => "Search poems"), start_form(), textfield(-name => 'q'); eval { my $dbh = DBI->connect($data_source, $username, $auth, \%attr); if ( param('q') ) { my $sth = $dbh->prepare(<<""); SELECT * FROM whatever WHERE this MATCHES ? $sth->execute( param('q') ); while ( my $row = $sth->fetchrow_hashref ) { # format and print the results } # OR mention you couldn't find anything } }; print h3("Couldn't execute querry! $@") if $@; print end_form(), end_html();