my $nr = 0; for (keys %hash) { last if $_ == $test; $nr++; }