use strict; use warnings; use Data::Dumper; my $params = [ 1, [ 2, 3, 4 ], 5 ]; use List::Util 'reduce'; sub multiplex { reduce { my $aref = ref($a) ? $a : [[$a]]; my $bref = ref($b) ? $b : [$b]; [ map { my $b_item = $_; map [ @$_, $b_item], @$aref } @$bref ] ; } @{shift()}; } print Dumper(multiplex($params)); #### sub multiplex { my $ret = [[]]; for (@{shift()}) { my $bref = ref($_) ? $_ : [$_]; $ret = [ map { my $b_item = $_; map [ @$_, $b_item], @$ret; } @$bref ]; } $ret; }