use strict; my %foo = (1 => 'value1',2 => 'value2',3 => 'value3'); #### print "$foo{$_}\n" foreach sort {$a <=> $b} keys %foo; #### sub sort_hash { my %hash = @_; #do the sorting part here, please help :) return %hash; } my %foo_sorted = sort_hash(%foo); print "$foo_sorted{$_}\n" foreach keys %foo_sorted;