http://www.perlmonks.org?node_id=1016360


in reply to regex on previous lines

File::ReadBackwards might make things easier for you.