$text = "This is not good,\n you know what I mean?\n\nThis should be on a separate line."; $text =~ s/[^\n](?:\n)|(\n)\n[^\n]/$1/g; print $text;