In versions of Perl up to and including 5, the proper way to refer to a hash element is
$hash{elem}. Using a
@ works but is less efficient; if you run perl with warnings (-w) you'll get a notice to that effect.
The foreach line should be spelled like this:
foreach my $key (keys %hash) {
Hope this helps.