use strict;
my $str = 'https://www.example.org/
http://example.com/
ca.gov
http://blade.example.com/bikes/airplane.php
http://alarm.example.com/
smugmug.com
shop-pro.jp
https://example.org/
qq.com
pcworld.com
symantec.com
360.cn
http://example.com/?brother=bike
http://www.example.com/behavior/bead.php
army.mil
https://example.com/boy/bedroom.php
https://example.com/
https://www.example.com/brother?activity=believe
https://www.example.net/achiever/bottle.html
http://believe.example.com/bit?bait=base&bone=ball
aboutads.info
http://www.example.com/
http://www.example.edu/afternoon
livejournal.com
http://border.example.com/box/afterthought
oaic.gov.au
https://www.example.edu/base.php
house.gov
smh.com.au
http://www.example.edu/
https://www.example.org/
lycos.com
https://border.example.com/?bridge=basket&blood=animal
hibu.com
http://example.com/';
my $regex = qr/^[^.\n]*[^\/\n]*\.\K[^\/\n]+/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