my @cleaned_AoA1 = map { grep length, @$_ } @AoA1; #### foreach (@AoA1) { @$_ = grep length, @$_; } #### sub make_scrubber { my ($aref) = @_; return sub { [ grep length, @$aref ] }; } my $iter = NestedLoops( [ map { make_scrubber($_) } @AoA1 ] );