use Algorithm::Loops qw( NestedLoop ); my @terms = NestedLoop(\@array, sub { join '', @_ }); print(join(', ', @terms), "\n");