# works -- a while loop might be more efficient/elegant MAX_BASES: while (@base_values) { # @base_values is consumed $max_bases .= $_->[1] for # append base of each max reduce { $a->[0] > $b->[0] ? $a : $b } # max in group map [ shift(@base_values), $_ ], @base_ord # groups of n ; }