#!/usr/bin/perl use strict; use warnings; my @error_array; my @sample_ids; my @merged_array; #Opening File Number 1 open (ERRORFILE,"<", "Errors-email.txt") || die "File not found\n"; @error_array = ; close ERRORFILE; #Opening File Number 2 open (CSV,"<", "Merged_CSVfiles.csv") || die "File not found\n"; @merged_array = ; close CSV; #Getting the sample ids foreach my $line(@error_array){ if($line =~ m/^Sample_identifier/){ $line =~ s/Sample_identifier//; $line =~ s/IRD.+:$//; $line =~ s/\///; $line =~ s/^\s//; $line =~ s/IRD.+$//; push(@sample_ids,$line); # print(@sample_ids); }# End of the if loop }#End of the for-each loop foreach my $records(@merged_array){ if($records =~ /$sample_ids[3]/){ print $records; } } #### Name,Building,Processing Date,Receipt Date, Location,Patient Id,Sample ID, John Doe,G building,05-Aug-2012,08-Aug-2012,New York City,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, #### foreach my $records(@merged_array){ if($records =~ /$sample_ids[3]/){ print $records; } #### ************************************** Errors for file: Merged_CSVfiles_1.txt ************************************** Sample_identifier 11SS00342 / IRD Clinic clinic_HIV000140180: * The following fields contain invalid values: Blah blah blah blah * Sample_identifier 11SS00336 / IRD Clinic clinic_HIV000140174: * The following fields contain invalid values: Yada yada yada * Sample_identifier 11SS00303 / IRD Clinic clinic_HIV000140141: * The following fields contain invalid values: yeah yeah yeah #### push(@sample_ids,$line); print(@sample_ids); #### push(@sample_ids,$line); }# End of the if loop }#End of the for-each loop print $sample_ids[3];