title: Perl Delete First Occurrence
body: <p>Okay so I want to delete the first occurrence of a string, let's say, "dog", in a file, and only the first occurrence.  So if the file reads:</p>
  
  <blockquote>
    <p>The dog was happy.<br>
    The dog liked to run.</p>
  </blockquote>
  
  <p>The output would be</p>
  
  <blockquote>
    <p>The was happy.<br>
    The dog liked to run.</p>
  </blockquote>
  
  <p>I have the following code:</p>
  
  <pre><code>#!/usr/local/bin/perl
  
  use warnings;
  use strict;
  
  my $file = $ARGV[0];
  my $out = $ARGV[1];
  
  open (IN, "&lt;$file");
  open (OUT, "&gt;$out");
  while(&lt;IN&gt;){
    s/dog/ /;
    print OUT $_;
  }
  
  close IN;
  close OUT;
  </code></pre>
  
  <p>And it works, but instead of repacing just the first instance, it replaces all instances of the word.  I thought I had to use the global modifier, g, to make it replace all instances?  Why is it replacing all instances of the string I'm searching for?  It's probably some simple error I'm not seeing.</p>