use strict; my $string = "DEFINITION BIO5 gene complete cds EC=1.7.7.1. ACCESSION D17396 VERSION D17396.1 GI:498167 KEYWORDS protein; insulin-like protein;"; my %KVpairs = ($string =~ /(\w+)\s+(.*)/mg);#save the result right into a hash foreach (keys %KVpairs) { print "[$_] = $KVpairs{$_}\n"; }