title: Matching the end of line $ in perl; print showing different behavior with chomp
body: <p>I am reading a file and matching a regex for lines with a hex number at the start followed by few dot separated hex values followed by optional array name which may contain an option index. For eg:</p>
  
  <blockquote>
    <p>010c10  00000000.00000000.0000a000.02300000  myFooArray[0]</p>
  </blockquote>
  
  <pre><code>while (my $rdLine = &lt;RDHANDLE&gt;) {
    chomp $rdLine;
  
    if ($rdLine =~ m/^([0-9a-z]+)[ \t]+([0-9.a-z]+)[ \t]*([A-Za-z_0-9]*)\[*[0-9]*\]*$/) {
    ...
  </code></pre>
  
  <p>My source file containing these hex strings is also script generated. This match works fine for some files but other files produced thru the exact same script (ie no extra spaces, formats etc) do not match when the last $ is present on the match condition.
  If I modify the condition to not have the end $, lines match as expected.</p>
  
  <p>Another curious thing is for debugging this, I added a print statement like this:</p>
  
  <pre><code>if ($rdLine =~ m/^([0-9a-z]+)[ \t]+/) {
      print "Hey first part matched for $rdLine \n";
  }   
  if ($rdLine =~ m/^([0-9a-z]+)[ \t]+([0-9.a-z]+)/) {
      print "Hey second part matched for $rdLine \n";
  }
  </code></pre>
  
  <p>The output on the terminal for the following input eats the first character :</p>
  
  <blockquote>
    <p>010000                             00000000  foo</p>
  </blockquote>
  
  <pre><code>   "ey first part matched for 010000                             00000000  foo
      ey second part matched for 010000                             00000000  foo"
  </code></pre>
  
  <p>If I remove the chomp, it prints the Hey correctly instead of just ey.</p>
  
  <p>Any clues appreciated!</p>