in reply to Combinations with variable length

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11132353 use warnings; my @static = qw( 1 2 ); my $nonstatic = 3; my @item = []; @item = map { my $static = $_; map [ $static, @$_ ], @item } @static for 1 .. $nonstatic; use Data::Dump 'dd'; dd \@item;

Outputs:

[ [1, 1, 1], [1, 1, 2], [1, 2, 1], [1, 2, 2], [2, 1, 1], [2, 1, 2], [2, 2, 1], [2, 2, 2], ]