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 } } #### while (<>) { my %params = map { my ($k,$v) = split /\s*=\s*/; $v =~ /(.+)\s+\((.+)\%\)/; ($k => [$1,$2]) } split /\s,\s*/; }