- or download this
my @lastmatches;
my $keep = 5;
...
push @lastmatches, $line;
unshift @lastmatches if --$keep < 1;
}
- or download this
my @lastfive = ( grep { /criteria/ } <FILEHANDLE> ) [ -5 .. -1 ];
- or download this
use strict;
use warnings;
...
close IN;
my $count = 5;
print $count--, ".: ", $_ foreach @lastfive;