foreach my $file (@filenames) my $filepath = "/FILEPATH/$file"; open my $fh, "<",$filepath or die("could not open log file: $!"); my $in = 0; while(<$fh>) { $in = 1 if /+=======+=======+============+============+============+/; print if($in); $in = 0 if /+-------+-------+------------+------------+------------+/; }