title: Why is Perl lazy when regex matching with * against a group?
body: <p>In perl, the <code>*</code> is usually greedy, unless you add a <code>?</code> after it.  When <code>*</code> is used against a group, however, the situation seems different.  My question is "why".  Consider this example:</p>
  
  <pre><code>my $text = 'f fjfj ff';
  my (@matches) = $text =~ m/((?:fj)*)/;
  print "@matches\n";
  # --&gt; ""
  @matches = $text =~ m/((?:fj)+)/;
  print "@matches\n";
  # --&gt; "fjfj"
  </code></pre>
  
  <p>In the first match, perl lazily prints out nothing, though it could have matched something, as is demonstrated in the second match.  Oddly, the behavior of <code>*</code> is greedy as expected when the contents of the group is just <code>.</code> instead of actual characters:</p>
  
  <pre><code>@matches = $text =~ m/((?:..)*)/;
  print "@matches\n";
  # --&gt; 'f fjfj f'
  </code></pre>
  
  <ol>
  <li>Note:  The above was tested on perl 5.12.</li>
  <li>Note:  It doesn't matter whether I use capturing or non-capturing parentheses for inside group.</li>
  </ol>