in reply to A single action from one or more items searched for

You're on the right path... you need to read up on last, next and LABELS in perlsyn.

I am concerned that you are not checking the success of you file opens. I promise it will save you time in the future if you slap an or die 'can not open file' at the end your opens



grep
Unix - where you can thrown the manual on the keyboard and get a command