use strict; use warnings; use List::MoreUtils 'minmax'; my %hash = ( ... ); # Absurdity is to find end values in order to avoid # numeric comparison. my ( $min , $max ) = minmax keys %hash; for my $i ( $min .. $max ) { ... }