in reply to Code Review Time!

As far as code review goes, the first thing to do is add
use warnings; use strict;
as others pointed out. It helps avoid the very type of problem you experience, and makes it easier for others, like us, to work with your code.

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh