This is why you should always use strict and lexical variables (aka my $x). Using strict would have helped you realize that the variables were not lexically scoped. Plus it's just good programming practice. :-) I use strict even on my throwaway scripts these days.