use strict;
my $str = '!-- The following setting enables collapsible lists -->
<p>
<a href="#human">Human</a></p>
<p class="collapse-section">
<a class="collapsed collapse-toggle" data-toggle="collapse"
href=#mammals>Mammals</a>
<div class="collapse" id="mammals">
<ul>
<li><a href="#alpaca">Alpaca</a>
<li><a href="#armadillo">Armadillo</a>
<li><a href="#sequence_only">Armadillo</a> (sequence only)
<li><a href="#baboon">Baboon</a>
<li><a href="#bison">Bison</a>
<li><a href="#bonobo">Bonobo</a>
<li><a href="#brown_kiwi">Brown kiwi</a>
<li><a href="#bushbaby">Bushbaby</a>
<li><a href="#sequence_only">Bushbaby</a> (sequence only)
<li><a href="#cat">Cat</a>
<li><a href="#chimp">Chimpanzee</a>
<li><a href="#chinese_hamster">Chinese hamster</a>
<li><a href="#chinese_pangolin">Chinese pangolin</a>
<li><a href="#cow">Cow</a>
<li><a href="#crab-eating_macaque">Crab-eating_macaque</a>
<div class="gbFooterCopyright">
© 2017 The Regents of the University of California. All
Rights Reserved.
<br>
<a href="https://genome.ucsc.edu/conditions.html">Conditions of
Use</a>
</div>';
my $regex = qr/<li><a.+?>(.+)?<\/.+>/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html