use strict;
my $str = 'cc14:e1d0:8636:b5fe:ed02:f308:c51b:b269
63e2:2a95:3ed0:f118:63d4:1f6d:e511:de13
2fdd:c32f:0358:ff64:da39:a7db:eb1f:fa94
e4df:0bdf:396c:56ef:fb1b:1207:c252:097c
a051:27e4:adef:3d55:a369:02c3:51de:ffd7
5fec:aff9:5978:0df9:3c8e:8095:1a8b:d513
dd3e:9802:1f77:2a0b:920b:88e7:5659:b0ac
3ff2:1f5c:9734:a0f1:338c:70d6:8a7b:40c2
e294:91e7:b044:daf1:b359:85fb:20ec:2c27
1b7c:b087:7f13:2be3:91fe:4ab1:b3f6:2c46
ad23:8fa2:da36:89ee:b9ec:c7eb:3037:0a84
f2a8:f88c:c0b8:8adf:a0d0:32e4:12ce:2d0d
aafe:fe3a:b6b7:9be9:ad2e:9400:100c:1759
15de:d06c:c69a:0bb7:3956:a99d:9b30:0b8c
fd1b:6def:0088:f055:b2ed:17d1:8f68:998a
6258:2b38:eb8b:9abf:6888:a88e:b016:3dec
fa16:99d3:afd3:c660:ede5:0e74:c499:6444
8e64:c77c:bd13:6264:8393:1675:bf47:668a
e861:f66e:8f9d:c133:b559:d9eb:8774:edce
efb8:6adf:a2ba:a311:af1c:caed:fd46:9738';
my $regex = qr/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/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