while ( $file = <>) { chomp $file; my $status = "open file"; open( MYFILE, $file ) or next; $status = 0; my $last = ""; while () { if(/ALARM:/) { print "$file:", $. - 1, ": $last"; print "$file:$.: $_"; $status++; } $last = $_; } close MYFILE; } continue { print "Done with $file : found $status error(s)\n"; }