use Algorithm::Loops; use Math::Combinatorics; my $fixed_size = 2; my @groups = ( [qw( A B C )], [qw( 1 2 3 4 )], [qw( yellow blue green )], [qw( tiny small medium large gigantic )], ); for my $fixed_size_groups ( combine( $fixed_size, @groups ) ) { Algorithm::Loops::NestedLoops $fixed_size_groups, sub { print "@_\n"; }; }