use Algorithm::Loops qw( NestedLoops ); my @AoA1 = ( [ 'a', 'b', 'c' ], [ 'd', 'e', '' ], [ 'f', 'g', '' ], [ 'h', '', '' ], ); my @AoA2 = NestedLoops(\@AoA1, sub { [ @_ ] } ); #### use Algorithm::Loops qw( NestedLoops ); my @AoA1 = ( [ 'a', 'b', 'c' ], [ 'd', 'e', '' ], [ 'f', 'g', '' ], [ 'h', '', '' ], ); my @AoA2; my $iter = NestedLoops(\@AoA1); my @list; while (@list = $iter->()) { push @AoA2, [ @list ]; }