foreach $subsubkey (sort %{$tophash{$value}{$value2}} ) { print "$subsubkey"; }