#!/usr/bin/perl -T use CGI qw(:standard); use CGI qw(warningsToBrowser fatalsToBrowser); my $file1 = param("fil1"); my $key1 = param("phr1"); my $st1 = param("str1"); print header, start_html(-title=>"Searching for a pattern in a file" , -bgcolor=>"#cccccc"); h1("Searching for a pattern in a file" ); if(param()) { my $file1 = param("fil1"); my $key1 = param("phr1"); my $st1 = param("str1"); my $i =0 ; open(FILE , "$file1") or die("could not open the file $!\n"); while() { my $st1 = do{local $/ , }; if($st1=~ m/$key1/) { $i++; print p("The pattern $key1 has been found $i times.\n"); } else { print p("The pattern $key1 has not been found.\n"); } print p " Try Again " ; } } else { print hr() , start_form(); print p("Enter the file name you wish to make a search into" , popup_menu("fil1" , ['file1' , 'file2' ,'file3' ,'file4'])); print p("Enter the key word you wish to search for " , textfield("phr1" , "")); print p(submit("go") , reset("clear")); print end_form() , hr(); } end_html();