push @{$stack{$key}}, $value; #### for my $key (keys %stack){ for my $value (@{$stack{$key}}){ # do stuff with $key and $value } }