The CSV file contents: # This is a comment followed by a blank line # this comment is followed by a run-on line with ^M's humpty dumpty sat on a rock^Mhumpty dumpty fell^MPoor humpty dumpty is busted all to hell The script in question: #!/usr/bin/perl use strict; # define the csv datafile name (and path if need be) my $csv = 'testing/testfile.csv'; # Process the CSV file &read_csv($csv); # All is well that exits zero... exit; sub read_csv { my @chunks; open(CONF, $csv); while(){ chomp; if (/^#/){ # Must be a comment, skip it next; } elsif (/^\s*$/) { # Only contains whitespace, skip it next; } elsif (/^M/){ # Contains dos/mac control characters my @lines = split /^M/, $_; for ( my $i = 0 ; $i <= $#lines ; $i++ ){ push(@chunks, $lines[$i]); } } else { # assumed to be a normal data line push(@chunks, $_); } print "Found data for ", scalar(@chunks), " lines in $csv\n\n"; } close(CONF); }