use Algorithm::Loops qw( NestedLoops ); my $i = NestedLoops(\@list); while (my @set = $i->()) { print(join(',', @set), "\n"); }