use strict; use warnings; use Text::CSV; my $fileStr = <new({binary => 1, eol => $/}); open my $io, "<", \$fileStr; my @headers = @{$csv->getline($io)}; while (my $row = $csv->getline($io)) { print "File line $.\n"; print " $headers[$_]: '$row->[$_]'\n" for reverse 0 .. $#$row; } #### File line 2 Comment: 'Comment with a comma, and stuff.' Colour: 'Blue' Name: 'Fred' Line: '1' File line 3 Comment: 'No comma so no need for quotes' Colour: 'Green' Name: 'Joe' Line: '2' File line 4 Comment: '"A comma, and quotes"' Colour: 'Red' Name: 'Bob' Line: '3' File line 6 Comment: 'Penultimate line, but split across two input lines' Colour: 'Yellow' Name: 'Sam' Line: '4' File line 7 Comment: 'And an ordinary line to finish' Colour: 'Violet' Name: 'Bill' Line: '5'