for my $pair ( sub { my @pairs; while (my ($k,$v) = each %h) { push @pairs, [$k,$v] } @pairs }->() ) { my ($k,$v) = @$pair; ... }