title: Perl Regular Expression to extract value from nested html tags
body: <pre><code>$match = q(&lt;a href="#google"&gt;&lt;h1&gt;&lt;b&gt;Google&lt;/b&gt;&lt;/h1&gt;&lt;/a&gt;);
  if($match =~ /&lt;a.*?href.*?&gt;&lt;.?&gt;(.*?)&lt;\/a&gt;/){
  $title = $1;
  }else {
  $title="";
  }
  print"$title";
  </code></pre>
  
  <p>OUTPUT: <code>Google&lt;/b&gt;&lt;/h1&gt;</code></p>
  
  <p>It Should be : <code>Google</code></p>
  
  <p>Unable to extract value from link using Regex in Perl, it could have one more or less nesting: </p>
  
  <pre><code>&lt;h1&gt;&lt;b&gt;&lt;i&gt;Google&lt;/i&gt;&lt;/b&gt;&lt;/h1&gt;
  </code></pre>
  
  <p>Please Try this:</p>
  
  <p>1) &lt;td>&lt;a href="/wiki/Unix_shell" title="Unix shell">Unix shell&lt;/a></p>
  
  <p>2) &lt;a href="http://www.hp.com">&lt;h1>&lt;b>HP&lt;/b>&lt;/h1>&lt;/a></p>
  
  <p>3) &lt;a href="/wiki/Generic_programming" title="Generic programming">generic&lt;/a>&lt;/td>);</p>
  
  <p>4) &lt;a href="#cite_note-1">&lt;span>[&lt;/span>1&lt;span>]&lt;/span>&lt;/a></p>
  
  <p>OUTPUT:</p>
  
  <p>Unix shell</p>
  
  <p>HP</p>
  
  <p>generic</p>
  
  <p>[1]</p>