Second- Did you use strict?
use strict requires an element of discipline in your coding, but it also catches a number of common problems.
Variables must be properly declared before use
Bareword identifiers must be subroutines, not strings
Symbolic references are forbidden