for (sort { $a->{RegionNum} <=> $b->{RegionNum} or $a->{AR} <=> $b->{AR} } grep $_->{RegionNum} == $RegionNum, @StatsArray) { $ARKey = $_->{AR}; # do stuff, no need to check the RegionKey. }