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