title: Why does this regex in perl work for one word but not another?
body: <p>I'm new to perl so please excuse me if my question seems obvious.  I made a small perl script that just examines itself to extract a particular substring I'm looking for and I'm getting results that I can't explain.  Here is the script:</p>
  
  <pre><code>use 5.006;
  use strict;
  use warnings;
  use File::Find;
  
  my @files;
  find( 
      sub { push @files, $File::Find::name unless -d; }, 
      "."
  );
  
  my @filteredfiles = grep(/.pl/, @files);
  
  foreach my $fileName (@filteredfiles)
  {
  open (my $fh, $fileName) or die "Could not open file $fileName";
  
  while (my $row = &lt;$fh&gt;)
  {
      chomp $row;
      if ($row =~ /file/)
      {
          my ($substring) = $row =~ /file\(([^\)]*)\)/;
          print "$substring\n" if $substring;
      }
  }
  
  close $fh;
  }
  
  # file(stuff)
  # directory(stuff)
  </code></pre>
  
  <p>Now, when I run this, I get the following output:</p>
  
  <pre><code>stuff
  [^\
  </code></pre>
  
  <ol>
  <li><p>Why is it printing the lines out of order?  Since the "stuff" line occurs later in the file, shouldn't it print later?</p></li>
  <li><p>Why is it printing that second line wrong?  It should be "<code>\(([^\</code>".  It's missing the first 3 characters.</p></li>
  <li><p>If I change my regex to the following: <code>/directory\(([^\)]*)\)/</code>, I get no output.  The only difference is the word.  It should be finding the second comment.  What is going on here?</p></li>
  </ol>