$ cat tst_del.pl use v5.14; use experimental "for_list"; my %h; @h{"a".."d"} = 1..4; my @a = values %h; my $once; $once = 0; for my $e (@a) { splice @a,0,2 unless $once++; say "A: $e"; } $once = 0; for my ($k,$v) (%h) { delete @h{"a".."b"} unless $once++; say "H: $k => $v"; } say "never reached"; $ perl tst_del.pl A: 1 A: 3 H: a => 1 H: d => 4 Use of freed value in iteration at tst_del.pl line 22. $ perl -v This is perl 5, version 38, subversion 2 (v5.38.2) #### If any part of LIST is an array, "foreach" will get very confused if you add or remove elements within the loop body, for example with "splice". So don't do that.