use Text::CSV_XS; my $csv = Text::CSV_XS->new; while(){ chomp; my @columns = split /\t/; $csv->combine( @columns ) or die "could not combine due to ",$csv->error_input()," in input\n"; print $csv->string, "\n"; } __DATA__ first second "hello" 100,000 bye He said "bye" #### first,second """hello""","100,000" bye,"He said ""bye""" #### first,second "hello",100,000 bye,He said "bye"