use strict;
my $str = 'CN=Lst-niketech.cis.splunk.admins,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Lst-niketech.cis.splunk.users,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Lst-NikeTech.CIS.SOC,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=ACL.Shareddata.CIS.Shared.Operations.WHQ.Change,OU=ACL,OU=Groups,DC=ad,DC=nike,DC=com|CN=Shareddata.CIS.Shared.WHQ.Change,OU=SharedData,OU=Groups,DC=ad,DC=nike,DC=com|CN=SharedMail.Information.Security.Incident.Reporting.WHQ,OU=SharedMail,OU=Groups,DC=ad,DC=nike,DC=com|CN=Lst-digitaltech.splunk.security.users,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Lst-digitaltech.splunk.security.lead,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Application.SolarWinds.Xerox.Nike.Users,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.Citrix.Nike.Employees.Users,OU=Citrix,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Nike.NikeTech.NIS.SecOps,OU=Nike,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.Splunk.CIS.Admin.Users,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=lst-Nike.Cloud.Change.Management,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Application.TimeTrack.Users,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=SharedMail.nismonitor.WHQ,OU=SharedMail,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.SCCM.Reporting.AM,OU=SCCM,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.Casper.Report.User,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.HR.Portal.ESS.NonRetail,OU=Portal,DC=ad,DC=nike,DC=com|CN=Application.HR.Portal.ESS.US,OU=Portal,DC=ad,DC=nike,DC=com|CN=Application.Hightail.Users,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Lst-FE.All,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Lst-All.Exchange.Mailboxes BEAVERTN-SVR-VB,OU=Lists,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.Citrix.WebEx.Users,OU=Citrix,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Lst-NikeTech.CIS.ITSecurity.All,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=Lst-Metaframe.Global.Users,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=SharedData.GIPS_AllStar.WHQ.Read,OU=SharedData,OU=Groups,DC=ad,DC=nike,DC=com|CN=Application.citrix.shared.webex.users,OU=Citrix,OU=Application,OU=Groups,DC=ad,DC=nike,DC=com|CN=Lst-NikeTech.CIS.SecOps,OU=Lists,OU=BEAVERTN,OU=OR,OU=USA,DC=ad,DC=nike,DC=com|CN=SharedMail.Firewall.Changes.WHQ,OU=SharedMail,OU=Groups,DC=ad,DC=nike,DC=com|CN=SharedMail.Nike.Information.Security.WHQ,OU=SharedMail,OU=Groups,DC=ad,DC=nike,DC=com|CN=SharedMail.IOS.SSLCert.Requests.WHQ,OU=SharedMail,OU=Groups,DC=ad,DC=nike,DC=com';
my $regex = qr/(?:CN=)(\w+)/p;
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