in reply to how to convert new line to ","

Rather than convert the new lines, we can think of a single new line as a field separator and a pair of new lines as a record separator. With that view, we can accumulate the fields and then display them in the desired (comma delimited) format once we reach the end of the record.
#!/usr/bin/perl use warnings; use strict; my(@accumulate) = (); while (<DATA>){ chomp; if (/^\s*$/) { print join(',', @accumulate), "\n"; @accumulate = (); } else {push(@accumulate, $_)} } if (@accumulate) {print join(',', @accumulate), "\n"} __DATA__ 1111 2222 3333 4444 5555 6666