perl -00pe 'chomp; s/\n/,/g; s/$/\n/' data.txt