$text =~ s/(?<=\b)\n(?=\n\b)//g; #### This is line1\n \n line3\n \n \n