$interval = ; #a number, typically on the order of 500 %HoHoA = ( 'I' => { $a => [4,10,200,6000,7000,7100], $b => [75,350,5900,6402,7110], $c => [0,95,5990,6450] }, 'II' => { $a => [lots of numbers], $b => [lots of numbers], $c => [lots of numbers] }, 'III' => { $a => [lots of numbers], $b => [lots of numbers], $c => [lots of numbers] } ); #### 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++; } } #### $interval = 500; %HoAoHoA = ( 'I' => [ {$a => [4,10,200], $b => [75,350], $c => [0, 95]}, {$a => [6000], $b =[5900], $c =>[5990]}, {$a => [], $b =[6402], $c =>[6450]}, {$a => [7000,7100], $b =[7110], $c =>[]},