title: Extract the IP from a log file
body: <p>I am writing code that extracts all the IP addresses from a log file. (The log file contains a list of domain names, IP addresses and MAC addresses.) Here's my code:</p>
  
  <pre><code>open(CONF, '&lt;', 'dhcpd.conf') or die "\n";
  my @ip;
  
  while(my $line = &lt;CONF&gt; ) {
      if ( $line =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ ) {
          @ip = $1;
      }
  
      print "@ip,\n";
  }
  
  close CONF;
  </code></pre>
  
  <p>The problem is that each IP address is printing 5 times. The output looks like:</p>
  
  <pre><code>10.0.0.158
  10.0.0.158
  10.0.0.158
  10.0.0.158
  10.0.0.158
  10.0.0.159
  10.0.0.159
  10.0.0.159
  10.0.0.159
  10.0.0.159
  ...
  </code></pre>
  
  <p>Is the problem at <code>@ip = $1</code>, or is it somewhere else?</p>