my $gb=new Bio::DB::GenBank; open my $handle, '<', 'sec.txt' or die !$; # check for success while ( my $line = <$handle> ) { # read one line at a time chomp $line; # strip new line chars print "Doing $line\n"; my $seq = $gb->get_Seq_by_id( $line ); write_sequence (">>roar.fa", 'fasta',$seq ); # ^^ # ( assuming write_sequence() supports appending ) } close $handle or die $!;