I cobbled the code together by breaking my problem into discrete tasks. I then started writing code to accomplish each task and testing the code to ensure it worked. As I got each task working I added code to accomplish the next task. I admit it only makes sense to me because I know what the original problem was and the steps I took to solve each task. It aint pretty. I have been writing small perl scripts for more than a year but I still don't consider myself the be a perl programmer.
I need to work through all the thoughtful suggestions I have received, and I thank everyone for their help.