title: Searching through file on Perl
body: <p>Okay so I need to read in a file, go through each line and find where there is the string ERROR.  This is what I have so far:</p>
  
  <pre><code>open(LOGFILE, "input.txt") or die "Can't find file";
  
  $title = &lt;LOGFILE&gt;;
  
  $\=' ' ;
  while (&lt;&gt;){
      foreach $title(split){
          while (/^ERROR/gm){
              print "ERROR in line $.\n";
          }
      }
  }
  close LOGFILE;
  </code></pre>
  
  <p>So the problem that I have is that it only looks at the first word of each line.  So if the input is</p>
  
  <p>boo far ERROR</p>
  
  <p>It won't register an error.  any help would be greatly appreciated!  I'm new to perl so please try and keeps things basic.  Thanks!</p>