use strict; use warnings; my $s = <<"GROK"; "boom" hello "" bill hello " " bill "baz \t hello jock" "boom2" abc "baz2 hello2 \t jock2 " GROK $s =~ s{"([^"]*)"} { if ($1 =~ tr/\n//) { my $x = $1; $x =~ s/[ \t]*\n[ \t]*/ /g; '"' . $x . '"'; } else { '"' . $1 . '"'; } }eg;