use blib; use Foo; use Data::Dump qw(dd); $h = {foo => 1, bar => 2}; while (($k,$v) = each %$h) { Foo::foo($h) if $k eq 'foo'; } dd $h; __END__ Use of each() on hash after insertion without resetting hash iterator results in undefined behavior, Perl interpreter: 0x224f010 at foo.pl line 6. { bar => 2, foo => 1, newkey => "foo" }