in reply to trying to convert from awk to perl

Your question has already been asked and answered on comp.lang.perl.misc.

You've even responded there, and gotten additional assistance.

It's rude to reinsert the original problem into a new venue without proper disclosure.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.