title: Is there a Perl shortcut to count the number of matches in a string?
body: <p>Suppose I have:</p>
  
  <pre><code>my $string = "one.two.three.four";
  </code></pre>
  
  <p>How should I play with context to get the number of times the pattern found a match (3)?  Can this be done using a one-liner?</p>
  
  <p>I tried this:</p>
  
  <pre><code>my ($number) = scalar($string=~/\./gi);
  </code></pre>
  
  <p>I thought that by putting parentheses around <code>$number</code>, I'd force array context, and by the use of <code>scalar</code>, I'd get the count. However, all I get is <code>1</code>.</p>