#!/usr/bin/perl use strict; use Bio::DB::Fasta; my $database; my $fasta_library; my %records; open IDFILE, "NBS_LRR_IDs.txt" or die $!; open OUTPUT, ">NC_003070_NBS-LRR.faa" or die $!; # name of the library file - (here it is hardcoded) $fasta_library = 'NC_003070_all_chr.faa'; # creates the database of the library, based on the file $database = Bio::DB::Fasta->new("$fasta_library") or die "Failed to create Fasta DP object on fasta library\n"; # now, it parses the file with the fasta headers you want to get while () { my ($id) = (/^>*(\S+)/); # capture the id string (without the initial ">") my $header = $database->header($id); #print "$header\n"; print ">$header\n", $database->seq( $id ), "\n"; print OUTPUT ">$header\n", $database->seq( $id ), "\n"; } exit;