use Algorithm::Loops qw( NestedLoops ); my @lists = ( [qw( a b )], [ 1..7 ], ); my @array = NestedLoops(\@lists, sub { 'log' . join('', @_) });