http://www.perlmonks.org?node_id=475112


in reply to Re: Ouch! Each! Reentrant it is not
in thread Ouch! Each! Reentrant it is not

You can avoid the scalar op and a useless variable by just calling keys in scalar context

Taking it one step further, it seems you can also call it in void context (which is maybe more efficient):

if ($val == 2 ){ keys %hash; return "The key for 2 is $key\n"; }