The other monks have given you great advice but you might also look in to using the graphical Perl debugger PTKDB
Using that has solved numerous problems I've had since you can step through the code and watch what's happening with your variables and how they change.
To disagree, one doesn't have to be disagreeable - Barry Goldwater