my $foo = do { local $/; <$fh> }; #### baz = (one two, three four, five six) #### baz = (one two, three four, five six) #### while ($foo =~ s/(\([^)]*)\n(.*?\))/$1$2/gs) {}