This sounds suspiciously homework-ish, so I'll point you towards some references which will help you work this out yourself:
perldsc
perlref
References quick reference
And for printing out the data structure try: Data::Dumper
Hope this helps, if you get stuck with code - post a reply with any erros / output that is appropriate and see what the Monastery comes up with.
Just a something something...