foreach my $sortedkey (sort {$hashname{"$a"} <=> $hashname{"$b"} } keys %hashname) { printf "Value: %d Key: %s", %hashname{"$sortedkey"}, $sortedkey; }