title: Counting occurrences of a word in a string in Perl
body: <p>I am trying to find out the number of occurrences of "The/the". Below is the code I tried"</p>
  
  <pre><code>print ("Enter the String.\n");
  $inputline = &lt;STDIN&gt;;
  chop($inputline);
  $regex="\[Tt\]he";
  if($inputline ne "")
  {
  
   @splitarr= split(/$regex/,$inputline);
  }
  
  $scalar=@splitarr;
  print $scalar;
  </code></pre>
  
  <p>The string is :</p>
  
  <blockquote>
    <p>Hello the how are you the wanna work on the project but i the u the
    The</p>
  </blockquote>
  
  <p>The output that it gives is 7. However with the string : </p>
  
  <blockquote>
    <p>Hello the how are you the wanna work on the project but i the u the</p>
  </blockquote>
  
  <p>the output is 5. I suspect my regex. Can anyone help in pointing out what's wrong. </p>