perl -i -pe 'BEGIN{$/="\n\n"} s/\n\n/\n/;' foo.txt #### perl -i -pe 'BEGIN{$/="\n\n";$\="\n"} chomp;' foo.txt