my $esc= qr[\e[^a-zA-Z]*[a-zA-Z]]; my $char= qr[(?:$esc)*.]; $_ .= $/; s[((?:$char){1,79})\s][$1\n]g; s[((?:$char){79})($char)][$1\n$2]g; chomp;