... open $fh ... $csv = Text::CSV_PP->new(); # create a new CSV parser object $csv->sep_char('|'); # look for the header line my $line = 0; my $col; while ($line < 20 && defined($col = $csv->getline($fh) )) { if ($csv->[0] eq '#') { # found it break; } $line++; } unless ($line < 20 && defined($col)) { die "header line not found\n"; } # process the rest of the file while (defined($col = $csv->getline($fh))) { ... }