-p processes the file one line at a time, while both of your regexp rely on matching two lines at a time. There are other problems with your regexps, but that's the biggest. That can be solved by working with more than one line at a time.
my $file = do { local $/; <> }; 1 while $file =~ s/^([ ]{4}[^\n]+)\n[ ]{4}/$1/m; print($file);
Or better yet:
my $file = do { local $/; <> }; 1 while $file =~ s/^(([ ]+)(?![ ])[^\n]+)\n\2(?![ ])/$1/m; print($file);
Note: The second will unwrap all pragraphs, no matter how far they are indented.
Note: Both work with and without -i.
Note: 1 while s///; is used in order to repeatedly match the same line. s///g; won't work when the paragraph is more than two lines long.
In reply to Re: replace \n with space to join indented lines
by ikegami
in thread replace \n with space to join indented lines
by olivier
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |