use strict; use Text::CSV_XS; use IO::File; my $csv = Text::CSV_XS->new(); my @row; while () { chomp; @row = split(/\|/, $_); $csv->print(\*STDOUT, \@row); print "\n"; } __DATA__ Field1|Field Number Two|Field Number Three|Field4 Another One|foo|fubar|foo and fubar