title: In Perl, how to count the number of occurences of successful matches based on a condition on their absolute positions
body: <p>Using just <strong>one</strong> Perl substitute or matching regular expression statement , how can we modify below code: </p>
  
  <p>I need to modify the value of <strong>$pattern</strong> in below code in a way that the code would count the number of times a successful match is found in the string provided that the absolute position of the successful match satisfies a certain condition.</p>
  
  <pre><code>$pattern = "F1";  
  $string = "F1234F12F1F1234F12F13";     
  $count = 0;      
  while ($string =~ /$pattern/g) {$count++} 
  print $count;
  </code></pre>
  
  <p>As an example for the condition on absolute position, you could think of:  </p>
  
  <p>ABSOLUTE_POSITION IS DIVIDABLE by 5</p>
  
  <p>In this case and based on the value of <strong>$string</strong> above, the output would be: 4.</p>
  
  <p><br></p>
  
  <p>Please note that once the code is complete, the only line changing on different conditions on absolute position of a successful match, would be the first line of the code.</p>
  
  <p>Thanks for any help</p>