use Algorithm::Loops qw( NestedLoops ); my $i = NestedLoops(\@arr); while (my @vals = $i->()) { print(join(' ', @vals), "\n"); }