open IN, "infile.dat"; open OUT, ">data.csv"; while () { chomp $_; my @fields = split(/|/, $_); my $newLine = join(",", @fields); print OUT "$newLine\n" } close IN; close OUT; #### hi|I'm with GNU,Inc.|I need a comma in my title this|will|produce|,|to|many|fields