in reply to last $n lines that match a criteria

Heh, what's CPAN good for if you don't use it?