use strict;
my $str = '<span style="color:rgb(128,0,0);font-weight:bold">> Оформлен заказ в магазине <a href="http://www.test1.com" target="_blank">test1.com</a> </spant-family:arial,sans-serif>
<a href="http://test.site.com/11222/sdf.html">http://www.test.site.com</a><br style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:12.8px"><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:12.8px">SOME MESSAGE TEXT</span><br style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:12.8px"><a href="http://www.test2.com/">www.test2.com/123/test</a>
SOME TEXT</span><br style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:12.8px"><a href="http://www.TEsst.com/">https://tesst.com</a><br style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:12.8px"><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:12.8px"> === =size:12.8px"><span style="color:rgb(0,0,0);font-family:arial,sans-serif;font-size:12.8px"><a href="http://site.org">site.org</a>
';
my $regex = qr/<a\s+href="https?:\/\/?(?:www\.)?((?:(?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,8})(?:"|\/).*?>(?:https?:\/\/)?(?:www\.)?\1/imp;
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