@c = sort { $b <=> $a } @c; my @runs; my $s = 0; while ($s <= 4) { my $e = $s+1; ++$e while $e <= 4 && $c[$e] == $c[$e-1] - 1; if ($e-$s > 1) { push(@runs, [ map { $c[$_] } $s..$e-1 ]); $lr_idx = $s; } $s = $e; } # Sort by length, then by highest. @runs = sort { @$b <=> @$a || $b->[0] <=> $a->[0] } @runs;