my @log_final; my $watching_for_last_match = 0; # ^ Bonus! This var will give a count of # entries within the timestamp at the end, # compare with scalar(@log_final) for stats while (my $log_line = $log_bckwards->readline) { if ( $watching_for_last_match ) { if ($log_line !~ /$TIMESTAMP/) { last; } } else { if ($log_line =~ /$TIMESTAMP/) { $watching_for_last_match++; } } unshift @log_final, $log_line; }