in reply to Iterating through files and arrays simultaneously

I assume those numbers are unqiue identifiers NOT ranges? Bio::SeqIO from Bioperl is going to be helpful if you are ever going to have sequences in different file formats.
use Bio::SeqIO; my $in = new Bio::SeqIO(-file => 'filename', -format => 'fasta'); my %seqs; my @idlist = qw(456-3210 4670-5490); while( my $seq = $in->next_seq ) { my $id = $seq->display_id; $id =~ s/gb\|//; $seqs{$id} = $seq; } my @seqlist = grep { defined } map { $seqs{$_} } @idlist;
If there are a LOT of sequences and you will be doing this repeatedly for different ID sets you can do this more efficiently with Bio::Index::Fasta.
use Bio::Index::Fasta; my $idx = new Bio::Index::Fasta(-filename => 'seqs.idx', -write_flag => 1); $idx->id_parser(\&myidparser); $idx->make_index($seqfile); my @idlist = qw(456-3210 4670-5490); my @seqlist; for my $id ( @idlist ) { if( my $seq = $idx->get_Seq_by_acc($id) ) { push @seqlist, $seq; } } # define your own ID parser if you wanted to strip out # the gb| part of the id # alternatively don't do this and make sure the IDs # you input exactly match the IDs of the sequences sub myidparser { if( $_[0] =~ /^>\s*gb\|(\S+)/ ) { return $1; } elsif ($_[0] =~ /^>\s*(\S+)/) { return $1; } else { return; } }