use strict; use warnings; my $previous; while (my $line = <$handle>) { if (defined($previous) && $line =~ /BEEP/ ) { print $previous; } $previous = $line; }
Of course you need additional code to extract the number from $previous, but that doesn't seem to be a problem for you.
Update: as ambrus++ pointed out in the CB this is a good place to use a continue block for assigning to $previous.
In reply to Re: How to match previous line
by moritz
in thread How to match previous line
by qnguyen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |