use strict; use warnings; my $hash={a=>{b=>1},c=>{d=>1}}; foreach my $key (keys %$hash) { print "$key\n"; foreach my $subkey (keys %{$hash->{$key}}) { print "\t$subkey\n"; } }