in reply to last $n lines that match a criteria

I am a lazy programmer. I would combine the Unix grep and tail utilities to do those kind of things with a one-liner. ;-)

my @lines = split /\n/, `grep criteria file.foo | tail -$i`;
Provided what you are searching for is not *too* complicated of cause.