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