#!/usr/local/bin/perl use strict; use warnings; my @array = (22, 66, 11); my %hash = (); my $i = 0; foreach my $item (@array) { $hash{$i} = $item; $i++; } #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;