#!/usr/bin/perl use strict; use warnings; my $text = <This is a line with a break.

This is a pre
with a break.

This is a line with a break.

EOT 1 while $text =~ s{^((?:(?!
).|
(?:(?!
).)*
)*?)\n}{$1
}is; print $text;