my $rex = qr/Fifth/; my @last_four; while(<DATA>) { push @last_four, $_; shift @last_four if @last_four > 4; print @last_four if $_ =~ $rex; } __DATA__ First Second Third Forth Fifth Sixth
In reply to Re: Get specified number of previous line text when encountered a text match in a file
by saintmike
in thread Get specified number of previous line text when encountered a text match in a file
by tariqahsan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |