Description
Remove all consecutive blank lines, leaving just one
perl6 -e '$*ARGFILES.slurp.subst(/\n+/, "\n\n", :g).say' example.txt
Actually, the code above literally says to take any single "\n" and replace it with "\n\n", so the overall effect is to convert a single-spaced document into a double-spaced document. However, the "+" quantifier in "\n+" in fact does enable the intended effect of collapsing multiple consecutive blank lines (>2) into just one blank line.
Here are two examples (below) that collapse multiple consecutive blank lines into just one blank line, without altering the over-all document spacing in either a single-spaced or double-spaced document:
perl6 -e '$*ARGFILES.slurp.subst(/\n\n+/, "\n\n", :g).say' example.txt
perl6 -e '$*ARGFILES.slurp.subst(/\n**2..*/, "\n\n", :g).say' example.txt
These two examples are just an intermediate fix for now. Obviously one would want more general code where the user can define "N" in an ostensibly "N-spaced" document, so it gets scanned to remove any extra ">N-spacing" returns (e.g. removing quadruple-spacing in a triple-spaced document).