in reply to number of matches

$count=scalar(my @dummy = $string=~m/$regex/g);
will count the matches. If you don't assign the pattern match to an array, m//g will interpret this as a scalar context and only return the first occurrence, and the scalar function will then return 1.