use strict; use Algorithm::Loops qw/ NestedLoops /; my @arrays = ( [qw/ a b c /], [qw/ d e /], [qw/ f g h /], [qw/ i /], [qw/ j k /], [qw/ l /], [qw/ m /], ); NestedLoops( [ map [ undef, @$_ ], @arrays ], sub { my $count = 0; my $string = join '', grep { defined && ++$count } @_; print $string if $count >= 4; }, );