use Data::Dumper; ## your @AoA here ... my @results = map { grep(/\n/, @$_) ? map([split "\n"], @$_) : $_ } @AoA; print Dumper( \@results );