#!/usr/local/bin/perl use strict; use warnings; my %hash = ( '1' => 22, '2' => 66, '3' => 11); my @keys = sort { $hash{$a} <=> $hash{$b} } keys %hash; my @ret = (); foreach my $key ( @keys ) { printf "%-20s %6d\n", $key, $hash{$key}; push @ret, $key; } print @ret;