sub foo { my ($hash1,$hash2) = @_; # cleaner dereference foreach (keys %$hash1) { print "$_ $hash1->{$_}\n"; } # preferred, if you need to access both while ( my ($key, $value) = each %$hash2 ) { print "$key $value\n"; } }