use strict; use Bio::DB::Fasta; my $db = new Bio::DB::Fasta( "Library.fa" ) # this should be the bigger file or die "Failed to create Fasta DB object on Library.fa\n"; open( IDLIST, "Name.fa" ); # this is the list of ID strings open( IDDATA, ">", "Name-sequences.fa" ) or die "Error opening Name-sequences.fa for output: $!"; while ( ) { my ($id) = (/^>(\S+)/); # capture the id string (without the initial ">") print IDDATA ">$id\n", $db->seq( $id ), "\n"; } #### use strict; my %falib; my $idstr; open( LIB, "Library.fa" ); while () { chomp; if ( /^>(\S+)/ ) { $idstr = $1; } elsif ( /^[acgt]+$/i ) { $falib{$idstr} .= uc(); # convert to upper-case } } open( IDLIST, "Name.fa" ); # this is the list of ID strings open( IDDATA, ">", "Name-sequences.fa" ) or die "Error opening Name-sequences.fa for output: $!"; while ( ) { my ($id) = (/^>(\S+)/); # capture the id string (without the initial ">") print IDDATA ">$id\n", $falib{$id}, "\n" if ( exists( $falib{$id} )); }