title: Regex matches but capture group remains uninitialized
body: <p>I am new to perl and regex. I think I understand the idea and how to use regex, but I got stuck on a problem while writing a script. I have content from some page and I am trying to read some information. </p>
  
  <pre><code>my @rows = split(/&lt;tr(\s)bgcolor=.{8}/,$content);
  
  foreach my $row(@rows){
      if( $row =~/&lt;td\s+nowrap\s+align=.*\s?(bgcolor=.*\s+)?&gt;\w*\s?&lt;\/td&gt;/ig){
      print $1;
      print $file_opt $row."\n";
  
      # there will be more code later on
      } 
  }
  </code></pre>
  
  <p>This gives me an error that <code>$1</code> is uninitialized. I understand that happens when pattern does not match the string. But i have regex under if - so if it enters the if, it does match, rigth? As you can see, i printed rows to a file. Each one looks like this:</p>
  
  <pre><code>&lt;td nowrap align="right"&gt;DOLNOŚLĄSKIE&lt;/td&gt;&lt;td nowrap align="right" bgcolor=#D0E0D0 &gt;0&lt;/td&gt;&lt;td nowrap align="right"&gt;0&lt;/td&gt;&lt;td nowrap align="right" bgcolor=#D0E0D0 &gt;0&lt;/td&gt;&lt;td nowrap align="right"&gt;0&lt;/td&gt;&lt;td nowrap align="right" bgcolor=#D0E0D0 &gt;0&lt;/td&gt;&lt;td nowrap align="right"&gt;0&lt;/td&gt;&lt;td nowrap align="right" bgcolor=#D0E0D0 &gt;0&lt;/td&gt;&lt;td nowrap align="right"&gt;0&lt;/td&gt;&lt;td nowrap align="right" bgcolor=#D0E0D0 &gt;0&lt;/td&gt;&lt;td nowrap align="right"&gt;4&lt;/td&gt;&lt;td nowrap align="right" bgcolor=#D0E0D0 &gt;0&lt;/td&gt;&lt;td nowrap align="right"&gt;1&lt;/td&gt;&lt;td nowrap align="right" bgcolor=#D0E0D0 &gt;1&lt;/td&gt;&lt;td nowrap align="right"&gt;3&lt;/td&gt;&lt;td nowrap align="right" bgcolor=#D0E0D0 &gt;6&lt;/td&gt;&lt;td nowrap align="right"&gt;1&lt;/td&gt;&lt;td nowrap align="right" bgcolor=#D0E0D0 &gt;2&lt;/td&gt;&lt;td nowrap align="right"&gt;1&lt;/td&gt;&lt;td nowrap align="right" bgcolor=#D0E0D0 &gt;19&lt;/td&gt;&lt;td nowrap align="right"&gt;0&lt;/td&gt;&lt;/tr&gt;
  </code></pre>
  
  <p>And all of unnecessary things from <code>$content</code> are not in a file. So does this pattern match or not?</p>