for $RomanNumeral (keys %HoHoA) { # For each key RomanNumeral for $letter (keys sort {$a <=> $b } %{$HoHoA{$RomanNumeral}} { # The sort will work here, because in this case, the $a, $b, etc are indices # For each lettered array in that key $i = 0; for ($i < length($HoHoA{$RomanNumeral}{$letter})-1) { $lowerlimit = $HoHoA{$RomanNumeral}{$letter}[$i]; $upperlimit = $interval + $lowerlimit; #Set a lower limit and an upper limit to the range of numbers we are looking for if ($element >= $lowerlimit && $element <= $upperlimit) { save $element's value to a new array, keyed by both $RomanNumeral and $letter $element here corresponds to all values in the hash %{HoHoA{$RomanNumeral}}, regardless of their $letter key. } $i++; } }