use Algorithm::Loops 'MapCar'; my @results = map { grep(/\n/,@$_) ? MapCar {[@_]} map([split "\n"], @$_) : $_ } @AoA; #### use Test::More tests => 1; my @AoA = ( [qw/single cell values/], [qw/are really easy/], [ "but\nmultiline\nstilton", "these\ncells\nis", "aren't\nsuck\ngreat" ], [qw/back to life/], [qw/back to reality with more cells/] ); my $desired = [ [ 'single', 'cell', 'values' ], [ 'are', 'really', 'easy' ], [ 'but', 'these', 'aren\'t' ], [ 'multiline', 'cells', 'suck' ], [ 'stilton', 'is', 'great' ], [ 'back', 'to', 'life' ], [ 'back', 'to', 'reality', 'with', 'more', 'cells' ] ]; use Algorithm::Loops 'MapCar'; my @results = map { grep(/\n/,@$_) ? MapCar {[@_]} map([split "\n"], @$_) : $_ } @AoA; is_deeply \@results, $desired, "The arrays match!";