title: Replace every nth Occurrence in a Perl Script
body: <p>I have text file with 10 lines. Each line has the word no_access and only that in it. I found a website that has syntax to replace every nth occurrence of some string. When I try to put it into a script, it spits out errors.</p>
  
  <p><a href="http://backreference.org/2012/08/22/replace-every-nth-occurrence/" rel="nofollow">Replace every Nth occurrence</a></p>
  
  <p>This is the script I have so far:</p>
  
  <pre><code>use strict;
  use warnings;
  
  while (&lt;&gt;) {
  my $count = 0; 
  s/no_access/(++$count % 3 == 0)?"read":$&amp;/ge;
  }
  print;
  </code></pre>
  
  <p>However, I get the error: Use of uninitialized value $_ in print. </p>
  
  <p>I tried the script without the print command, but nothing happens. How do I get this script to run and perform the replacement of every third "no_access".</p>