while () { $ptfkey = $_; # you can skip this using above suggestion $ptfpn = $ptfkey; # don't need this if just matching $ptfpn =~ m/^(\w+)/; # if only letters and numbers $ptfpn =~ m/^([\d\-\.]+)/; # if it's a float $F1hash{$1} = 1; }