#!/usr/bin/perl -w use strict; use warnings; use diagnostics; #-verbose; use Text::CSV; my $out = "Rows_of_interest.txt"; open (OUT, "+>$out"); open my $fh, "<", "gridall.csv" or die "gridall.csv: $!\n"; my $all_lines; my $matched_line_count; my $csv = Text::CSV->new({ binary => 1 }); while (my $row = $csv->getline ($fh)) { $all_lines++; $row->[8] =~ m/^CE$/ or next; print OUT $row; $matched_line_count++; } $csv->eof or $csv->error_diag (); print "\n\nNumber of lines detected:\t"; print $all_lines; print "\n\n"; print "\n\nNumber of matched lines detected:\t"; print $matched_line_count; print "\n\n"