my $text = do { local $/; <> }; $text =~ tr/\n//d; $text =~ s/(.{80})/$1\n/g; $text =~ s/(?!<\n)\z/\n/; print($text);