#!/usr/local/bin/perl use strict; use Text::CSV_XS; use FileHandle; my $infile = "foo.csv"; my $IN = new FileHandle; open ( $IN, "<$infile") or die "can't read $infile: $!"; my $c = 0; my $csv = Text::CSV_XS->new( {'binary' => 1}); while ( my $cols_aref = $csv->getline( $IN ) ) { my @a = @{$cols_aref}; print "$a[0],$a[1],$a[2]\n"; $c++; # Alternative way to assure exiting loop exit if ( $c > 5 ); } exit; ## My foo.csv Fred,foo,3 Tom,bar,4 ## Output: Fred,foo,3 Tom,bar,4 ,, ,, ,, ,,