use strict;
my $str = '> ls -d midlandls.pncint.net
[pasum60ad02.pncint.net]
midlandls.pncint.net. SOA vasan60ad03.pncint.net ip.address.request.pncbank.com. (562550790 10800 3600 1209600 60)
midlandls.pncint.net. NS vaash60ad04.pncint.net
midlandls.pncint.net. NS pasum60ad11.pncint.net
midlandls.pncint.net. NS pasum60ad01.pncint.net
midlandls.pncint.net. NS pasum60ad02.pncint.net
arcs-msmq CNAME weka357w.prod.pncint.net
bar-rpt CNAME wbar303a.prod.pncint.net
Bin CNAME services-gf2.midlandls.pncint.net
cigna-msmq CNAME welm350w.prod.pncint.net
citigroup-msmq CNAME welm352w.prod.pncint.net
Cwm CNAME services-gf2.midlandls.pncint.net
Cwm-app CNAME services-gf2.midlandls.pncint.net
cwm-rpt CNAME wcwm316a.prod.pncint.net
dbank-msmq CNAME welm344w.prod.pncint.net
egs CNAME egs-gf0.midlandls.pncint.net
egs-gf0 A 10.15.5.238
egs-gf1 A 10.38.5.238
egs-snat-gf0 A 10.15.7.238
egs-snat-gf1 A 10.38.7.238
eka CNAME services-gf2.midlandls.pncint.net
elm CNAME services-gf2.midlandls.pncint.net
fdic-msmq CNAME welm358w.prod.pncint.net
genworth-msmq CNAME welm365w.prod.pncint.net
icsg-msmq CNAME welm375w.prod.pncint.net
iru CNAME services-gf2.midlandls.pncint.net
iru-rpt CNAME wiru307a.prod.pncint.net
mat CNAME services-gf2.midlandls.pncint.net
mat-app CNAME services-gf2.midlandls.pncint.net
mat-rpt CNAME wmat302a.prod.pncint.net
mde CNAME services-gf2.midlandls.pncint.net
mde-internet CNAME services-gf2.midlandls.pncint.net
mfn CNAME services-gf2.midlandls.pncint.net
mfn-app CNAME services-gf2.midlandls.pncint.net
mfn-rpt CNAME wmfn318a.prod.pncint.net
mis CNAME services-gf2.midlandls.pncint.net
mis-app CNAME services-gf2.midlandls.pncint.net
mis-rpt CNAME wmis308a.prod.pncint.net
mls-msmq CNAME weka353w.prod.pncint.net
mvm CNAME services-gf1.midlandls.pncint.net
mvm-rpt CNAME wmvm302a.prod.pncint.net
pii CNAME services-gf2.midlandls.pncint.net
pnc-msmq CNAME weka373w.prod.pncint.net
pnclms-msmq CNAME weka349w.prod.pncint.net
rdt CNAME services-gf1.midlandls.pncint.net
services-gf1 A 10.26.64.229
services-gf2 A 10.28.8.229
services-snat-gf1 A 10.26.68.249
services-snat-gf2 A 10.28.12.227
wdunlop-msmq CNAME welm31bw.prod.pncint.net
wlm CNAME services-gf2.midlandls.pncint.net
wlm-app CNAME wwlm305w.prod.pncint.net
wlm-rpt CNAME wwlm306a.prod.pncint.net
midlandls.pncint.net. SOA vasan60ad03.pncint.net ip.address.request.pncbank.com. (562550790 10800 3600 1209600 60)
';
my $regex = qr/(?:
^
\s*
(?<host>[\w-\.]*)
\s*
(?<rectype>\w*)
\s*
(?<value>[\w\.-].*)
\s*$
)/mxp;
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