First of all, it looks like you're not useing strict. Always use strict.
Then if you're following this advice and using use strict you need to declare all the hashes, arrays, whatever that you want to be acessed globally, outside the subroutines, and those you don't want to be globally acessed, declare them inside the subroutines.