title: How can I extract data from HTML tables in Perl?
body: <p>I'm trying to use regular expressions in Perl to parse a table with the following structure.  The first line is as follows:</p>
  <pre><code>&lt;tr class=&quot;Highlight&quot;&gt;&lt;td&gt;Time Played&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;Artist&lt;/td&gt;&lt;td width=&quot;1%&quot;&gt;&lt;/td&gt;&lt;td&gt;Title&lt;/td&gt;&lt;td&gt;Label&lt;/td&gt;&lt;/tr&gt;
  </code></pre>
  <p>Here I wish to take out &quot;Time Played&quot;, &quot;Artist&quot;, &quot;Title&quot;, and &quot;Label&quot;, and print them to an output file.</p>
  <p>I've tried many regular expressions such as:</p>
  <pre><code>$lines =~ / (&lt;td&gt;) /
         OR
  $lines =~ / &lt;td&gt;(.*)&lt; /
         OR
  $lines =~ / &gt;(.*)&lt; /
     
  </code></pre>
  <p>My current program looks like so:</p>
  <pre><code>#!perl -w
  
  open INPUT_FILE, &quot;&lt;&quot;, &quot;FIRST_LINE_OF_OUTPUT.txt&quot; or die $!;
  
  open OUTPUT_FILE, &quot;&gt;&gt;&quot;, &quot;PLAYLIST_TABLE.txt&quot; or die $!;
  
  my $lines = join '', &lt;INPUT_FILE&gt;;
  
  print &quot;Hello 2\n&quot;;
  
  if ($lines =~ / (\S.*\S) /) {
  print &quot;this is 1: \n&quot;;
  print $1;
      if ($lines =~ / &lt;td&gt;(.*)&lt; / ) {
      print &quot;this is the 2nd 1: \n&quot;;
      print $1;
      print &quot;the word was: $1.\n&quot;;
      $Time = $1;
      print $Time;
      print OUTPUT_FILE $Time;
      } else {
      print &quot;2ND IF FAILED\n&quot;;
      }
  } else { 
  print &quot;THIS FAILED\n&quot;;
  }
  
  close(INPUT_FILE);
  close(OUTPUT_FILE);
  </code></pre>