#!perl use warnings; use strict; use Algorithm::Loops 'NestedLoops'; my @symbol = ( [ 'a', 'b', 'c' ], [ 'a', 'b', 'c' ], [ 'a', 'b', 'c' ], [ 'c', 'd', 'e' ], ); my $combos = NestedLoops([ $symbol[0], map { my $_hold = $_; sub { [grep {$_ ge $_[$#_]} @{$symbol[$_hold]}] } } 1..$#symbol ]); my @result; print "@result\n" while @result = $combos->();