in reply to Matching Regular expression at EOF

If the file isn't huge, simplicity is the way to go:
my $last = (map {/^.*(pat)/} <>)[-1];
Or maybe the file is huge, but the pattern is simple. Then there's still a simple solution:
my ($last) = (`grep pat file`)[1] =~ /^.*(pat)/;
Or
use autodie; open my $fh, "<", "file"; my $last; while (<>) { $last = $1 if /^.*(pat)/; }