my $count = 0; for ( values %default ) # don't really need to know the keys { $count++; my $total_c = substr( $_, rindex( $_, '|' )+1 ); # assume that "group" is an array of hashes: my $groupid = 0; for my $limit ( 750, 1000, 2000, 5000, 10000 ) { if ( $total_c < $limit ) { last; } else { $groupid++; } } $group[$groupid]{$count} = $_; }