while (<>) { my @params = split /\s*,\s*/; foreach my $param (@params) { $param =~ /(Identities|Positives|Negatives)\s+=\s+(.+)\s+\((.+)\%\)/; # $1 now contains which type you matched, $2 and $3 are the submatches, do what you will with them } }