Thank you, I will work on trimming it up and trying to reduce the amount of lines I have. I ran it through PerlTidy now its spiting out a bunch of use of uninitialized value $Z so at least now I have some more direction with it and a better idea of how to submit my code for help.
The most important first step for us is if you could provide code that compiles, which means that it does not give an error when you run it through perl -c scriptname.pl.