foreach my $records(@merged_array){ if($records =~ /$sample_ids[3]/){ print $records; }