Perl one-liner for adding newlines to HTML

This post was written by eli on March 12, 2026
Posted Under: Internet,perl,Rich text editors

When the rich editor puts all HTML in one line, and I want to edit it, I could always use the “tidy” utility, however it does too much. All I want is a newline here and there to make the whole thing accessible.

So this simple one-liner does the job:

perl -pe 's/(<\/(?:p|h\d|div|tr|td|table|ul|ol|li)>)/"$1\n"/ge'

Not perfect, but gives something to work with.

Add a Comment

required, use real name
required, will not be published
optional, your blog address