# If you have any spare characters to use # (lets say '~') sub my_squish { local $_ = shift; s/\n{2}/~/g; s/\s+/ /g; s/~/\n\n/g; $_; }