in reply to Extract the matching strings

From what you describe, it doesn't appear that a general solution is necessary in terms of parsing this - you only are asking for 2 parameters. I would keep it simple and add more complex stuff when needed. You don't say whether there are multiple records like this in the file or whether this is some kind of "header per file". If there are multiple records like this in the file, then some modifications are needed.

But basically look for the keywords and if found, use split to extract either the 2nd thing on the line or the last thing on the line. All sorts of complex things are possible, but if you don't need them, then don't do it!

#!/usr/bin/perl -w use strict; my $protname; my $rna; while (<DATA>) #while (<PROTEIN>) 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 . ....