foreach my $key1 (sort keys %hash){ foreach my $key2 (sort keys %{$hash{$key1}}){ print "$key1\t$key2\t$hash{$key1}{$key2}\n"; } }