in reply to The complicated problem

A recent and related discussion is How to retain perl in-house code. I suggest you read it.

Your code looks like a total mess. You don't mention your reasons for migrating, but you must fully understand what it does and what it should do (not always the same) in order to be able to transform it. Pick up a copy of a Perl book, and start reading up on topics like Best Practices.

Ten Essential Development Practices (perl.com, by Damian Conway, July 14, 2005) might be a good start.

--
Andreas