#!/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; } }