title: Counting Sentences/Words in Perl Using Regex
body: <p>This regex thing is getting old. :(
  Yet another question:
  I need to count the number of words and number of sentences in a paragraph. The code I tried using was this:</p>
  
  <pre><code>my $sentencecount = $file =~ s/((^|\s)\S).*?(\.|\?|\!)/$1/g;
  my $count = $file =~ s/((^|\s)\S)/$2/g;
  print "Input file $ARGV[1] contains $sentencecount sentences and $count words.";
  </code></pre>
  
  <p>My results return 63 for both counts. I know this is incorrect, as least as far as word count goes. Is this a result of using a substitution for the counting process? If so, how do I correct this?</p>