in reply to each function
Elaborating: each returns a key/value pair, so you need to:
while (my ($k,$v) = each %hash) [download]
Though in a scalar context, each returns just the key, but I think keys is more readable:
for (keys %hash) [download]