If your data is always going to have that number of fields, you can just work from the front and the back and comma-join all the bits in the middle. perl -F, -lane'chomp;print join("|",@F[0..2], join(",", @F[3..$#F-4]),@F[-3..-1])' A/NSRLFile.txt
Comment on Re: swapping PIPE for comma in CSV file