#!/usr/bin/perl use strict; use warnings; $|=1; ## turn off buffering for STDOUT use Text::CSV_XS qw( csv ); my $csv = Text::CSV_XS->new(); #using the defaults while (my $line = ) { if ($csv->parse($line)) { my @fields = $csv->fields(); print join ("|",@fields),"\n"; } else { warn "Line could not be parsed: $line\n"; } } =Prints: 1|Rat Control ;tag=gK004bb052|9 2|"Rat Control" ;tag=gK004bb052|9 3|Rat Control ;tag=gK004bb052|9 Line could not be parsed: 4,"Rat Control" ;tag=gK004bb052,9 5|123,456|abc 6|Rat|xyz 7|Rat Control|xyz Line could not be parsed: 8,""Rat Control" ;tag=gK004bb052",9 =cut __DATA__ 1,Rat Control ;tag=gK004bb052,9 2,"""Rat Control"" ;tag=gK004bb052",9 3,Rat Control ;tag=gK004bb052,9 4,"Rat Control" ;tag=gK004bb052,9 5,"123,456",abc 6,"Rat",xyz 7,"Rat Control",xyz 8,""Rat Control" ;tag=gK004bb052",9