use Data::Dumper; use strict; my $hash = {}; for (1..100) {#keys are all numbers, from the users' point of view $hash->{$_} = "a"; } my @keys = keys %$hash;#this is the internal order, I don't care print(join(",", @keys)); print "\n", "=" x 70, "\n"; my @sorted = sort @keys;#this will sort as strings!! print(join(",", @sorted)); print "\n", "=" x 70, "\n"; my @sorted_as_num = sort {$a <=> $b} @keys;#force it to sort as number print(join(",", @sorted_as_num)); print "\n", "=" x 70, "\n"; print Dumper($hash);