use strict;
my $str = 'https://testing.go.id/kantal-(1)(2)
(e.g. https://testing.go.id/beginilah-jika-kita-suka-haha)
https://green.kumparan.com/kantal-(1)(2)
(e.g. https://green.kumparan.com/kantal-(1)(2))
(e.g. https://green.kumparan.com/beginilah-jika-kita-suka-haha)
https://green.kumparan.com/kantal-(1)(2)
(e.g. https://green.kumparan.com/beginilah-jika-kita-suka-haha.jpg?haha=hoho&hehe$)
https://blue.kumparan.com/kantal-(1)(2)
(e.g. https://blue.kumparan.com/kantal-(1)(2))
(e.g. https://blue.kumparan.com/beginilah-jika-kita-suka-haha)
https://blue.kumparan.com/kantal-(1)(2)
(e.g. https://blue.kumparan.com/beginilah-jika-kita-suka-haha)
https://blue.kumparan.com/image/upload/f_jpg,fl_progressive,fl_lossy,c_fill,g_face,q_auto:best,w_480,ar_5:7/v1554524445/r6dxtztvmtw9by9oaibe.jpg
url(https://blue.kumparan.com/uikit-assets/assets/logos/404-653d82fd9ae91d1d6cf474e4fd929e47.png)
https://green.kumparan.com/image/upload/fl_progressive,fl_lossy,c_fill,q_auto:best,w_480,ar_5:7/v1553692790/jpgffb7pcs8yo7v0rs2y.jpg
url(https://green.kumparan.com/image/upload/fl_progressive,fl_lossy,c_fill,q_auto:best,w_640/v1554524445/r6dxtztvmtw9by9oaibe.jpg)';
my $regex = qr/https?:\/\/\S+\.[^()]+(?:\([^)]*\))*/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