use strict;
my $str = '<div id="breadcrumbs" class="col-xs-12"> <div class="col-xs-9 no_padding "> <a href="/">Home</a> › <a href="http://www.mudah.my/Pahang/for-sale" itemprop="url" title="See all ads in Pahang"> Pahang </a> › <a href="http://www.mudah.my/Pahang/Shoes-for-sale-4160" itemprop="url" title="See all ads in Shoes category">Shoes</a> › Nike AIr Presto Khaki </div> <div class="col-xs-3 no_padding "> <div class="prev-next"> <span class="nohistory"> <a href="http://www.mudah.my/Pahang/nike+air-for-sale?fs=1&lst=0&so=1&q=nike+AIR">Back to Results</a> </span> <span class="thin_pipe">|</span> <span class="nohistory"> <a id="go_next" href="http://www.mudah.my/Nike+AIr+Presto+Khaki-52071755.htm?st=s&cg=0&q=nike+AIR&lst=0&fs=1&w=107&cg=0&q=nike+AIR&so=1&st=s&ca=7_s&next=1">Next Ad»</a> </span> </div> </div> </div>';
my $regex = qr@<a[^>]*href="[^"]*(?<id>(?<=-)\d+)[^>]*>(?<name>[^<]*)</a@imsp;
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