open(FILE, "$some_dirr/$file") or die("can't open $file"); my ($PASSmatch, $sweepsmatch, $Finalmatch); while () { if (/\bPASS\b/) { $PASSmatch = 1; } elsif (/\bsweeps\b/) { $sweepsmatch = 1; } elsif (/\bFinal\b) { $Finalmatch = 1; } } close(FILE); if ($PASSmatch && $sweepsmatch && $Finalmatch) { # do whatever with this file. }