in reply to array of hashes

For an example of the same problem see parse xml and store data in array of hashesh

To learn how to avoid this problem see:

Tutorials: Getting Deeper Into Perl: Variable Scoping in Perl: the basics

Tutorials: Getting Deeper Into Perl: Coping with Scoping

For syntax see Tutorials: References quick reference, also covered in detail in Chapter 7 of http://learn.perl.org/books/beginning-perl/