#!/usr/bin/perl -w use strict; my $protname; my $rna; while () #while () in your case { if (/^VERSION/) { $protname = (split)[1]; } elsif (/^DBSOURCE/) { $rna = (split)[-1]; } } print "protname = $protname\n"; print "rna = $rna\n"; __END__ PRINTS: protname = YP_001648463.1 rna = NC_010202.1 __DATA__ LOCUS YP_001648463 258 aa linear INV 17-JUN-2009 DEFINITION cytochrome c oxidase subunit II [Ephydatia muelleri]. ACCESSION YP_001648463 VERSION YP_001648463.1 GI:164420795 DBLINK Project: 28177 DBSOURCE REFSEQ: accession NC_010202.1 KEYWORDS . ....