sub foo { my $hash_ref = shift; print "$_\n" for values %$hash_ref; } #### sub foo { my $hash_ref = shift; while ( my ( $key, $val ) = each %$hash_ref ) { # do something with $key and $val } }