use Modern::Perl; use Text::CSV; my @Sample_Ids_m; my $csv = Text::CSV->new( { binary => 1 } ) # should set binary attribute. or die "Cannot use CSV: " . Text::CSV->error_diag(); while ( my $row = $csv->getline(*DATA) ) { push @Sample_Ids_m, $row->[6]; # Element 6 is the ID } say for @Sample_Ids_m; # Print the collected IDs __DATA__ John Doe,G building,05-Aug-2012,08-Aug-2012,"New York City, NY",ABC2345,UCD23467, John Moe,H building,05-Aug-2012,08-Aug-2012,New York City,DEF2345,UCD80645, John Slo,I building,05-Aug-2012,08-Aug-2012,New York City,GHI2345,UCD76765, John Hor,j building,05-Aug-2012,08-Aug-2012,New York City,JKL2345,UCD87111, #### UCD23467 UCD80645 UCD76765 UCD87111 #### use Modern::Perl; use Text::CSV; my @Sample_Ids_m; my $csv = Text::CSV->new( { binary => 1 } ) # should set binary attribute. or die "Cannot use CSV: " . Text::CSV->error_diag(); open my $fh, "<", "Merged_CSVfiles.csv" or die "Merged_CSVfiles.csv: $!"; while ( my $row = $csv->getline($fh) ) { push @Sample_Ids_m, $row->[16]; # Element 16 is the ID } $csv->eof or $csv->error_diag(); close $fh; say for @Sample_Ids_m; # Print the collected IDs