$line =~ m/(?: # Collect heading fields [^;]+ # delimited by semicolons ; ){1} # In your case, there is only one field before the interesting field = # followed by a "=" (\d+) # and followed by our numbers, stuff them into $1 ; # and delimited by another semicolon /x;