This is more of a reply to the OP:
It's important to note that this code will not work when strict is enabled, and strict should always be turned on - in fact, modern versions of Perl turn it on for you if you say use v5.12; or higher at the top of the script. (See also Use strict and warnings)
Disabling strict is something that should only be done if you know what you are doing and why. In this case, others have already explained why there are much better ways to do what you want.
-- Hauke D