use Algorithm::Loops 'MapCarMin'; %hash = MapCarMin {@_} [ 0 .. keys %hash ], [ @hash{ sort {$a<=>$b} keys %hash } ];