my %hash; $hash{A}{A} = 1; $hash{A}{B} = 2; $hash{B}{A} = 4; $hash{B}{B} = 8; foreach my $k (keys %{$hash{B}}) { print "$k - $hash{B}{$k}\n"; }