use strict; use File::Find; my $count; my $path = "C:/hello/"; my $output = $path."Output.txt"; my $input = $path."Input.txt"; START: print ("Enter the name of your file >> "); chomp (my $name = ); if(length($name)==0) { print (STDERR "\nYour did not respond!!\n"); goto START; } else { my $spath = $path.$name; open(FM, ">$output") && open(AM, ">$input") || die ("Cannot open, $!\n"); find(\&search, "$spath"); close FM; open(SW, $output)||die ("Cannot open, $!\n"); while() { my $flag = 1; chomp; if (open(ETA, $_)) { $count = 0; while() { foreach($_){$count++;}; if (($_ ne "Dave") && ($count <= 20)) { $flag = 0; } } if ($flag == 0) { #I am trying to print the name of the file containg "Dave" in the first 20 lines print (AM "$_\n"); } } else { die ("Cannot open [$_], $!\n"); } }close AM; close SW; } sub search { if (((/\.c/)&&(!(/\.com/)))|(/\.h/)|(/\.pr/)) { print (FM "$File::Find::name\n"); } }