#!/usr/bin/perl use warnings; use Bio::Perl; use Bio::Seq; use Bio::SeqIO; # Reading the first file and store it into a hash #the sequence header is stored in the hash key and sequence is stored in the value my $FastaFile1 = Bio::SeqIO->new(-file => "test.fa", -format => 'fasta', -alphabet => 'dna') or die "Failed to create SeqIO object from \n"; my %fastaH1 =(); while( my $seqFile1 = $FastaFile1->next_seq() ) { unless (exists $fastaH1{$seqFile1->display_id."\t".$seqFile1->desc}) { $fastaH1{$seqFile1->display_id."\t".$seqFile1->desc} = $seqFile1->seq; #key of the hash is fasta header (all line) and value is sequence. } } # printing the fasta headers print "stored fasta headers:\n"; foreach my $key (keys %fastaH1){ print "$key\n"; } # reading the codes.txt file and creating the array open my $file, '<', "codes.txt"; chomp(my @lines = <$file>); close $file; print "stored organism codes\n"; foreach (@lines) { print " $_\n"; } # if each code is found on the hash print match is found foreach my $line (@lines) { chomp $line; if( exists $fastaH1{$line} ){ print "match found\n"; } }