use strict; use warnings; our %hash = ( 1=> 2, 3=>4 ); sub find_2{ while (my ($key,$val) = each(%hash)) { return "The key for 2 is $key\n" if $val == 2; } die "could not find 2"; } print find_2; print find_2; #### The key for 2 is 1 could not find 2 at each.pl line 11. #### if ($val == 2){; #rewind each my $a = scalar keys %hash; return "The key for 2 is $key\n" }