#... for my $range (sort { $a <=> $b } keys %$ranges) { ...