http://www.perlmonks.org?node_id=1061064


in reply to regular expression: match multiple newlines

Try:

s/\n{2,}/EEEEE/g

Output on your dataset:

dogs rats catsEEEEEfish

The \n{2,} notation matches 2+ newlines.

Edit: My apologies. Didn't notice the the OP's mentioning the possibility of other whitespace between the newlines.