use strict;
my $str = 'agamerica-qa.commloanservices.com.
====================================
agamerica-qa.commloanservices.com. 3600 IN SOA dns001.pnc.com. hostmaster.pnc.com. 543792585 1200 180 1209600 600
agamerica-qa.commloanservices.com. 86400 IN NS dns002.pnc.com.
agamerica-qa.commloanservices.com. 86400 IN NS dns001.pnc.com.
agamerica-qa.commloanservices.com. 86400 IN NS dns000.pnc.com.
bin.agamerica-qa.commloanservices.com. 30 IN CNAME gf0.agamerica-qa.commloanservices.com.
gf0.agamerica-qa.commloanservices.com. 3600 IN A 161.150.124.249
agamerica-qa.commloanservices.com. 3600 IN SOA dns001.pnc.com. hostmaster.pnc.com. 543792585 1200 180 1209600 600
agamerica.commloanservices.com.
====================================
agamerica.commloanservices.com. 3600 IN SOA dns001.pnc.com. hostmaster.pnc.com. 543792587 1200 180 1209600 600
agamerica.commloanservices.com. 86400 IN NS dns002.pnc.com.
agamerica.commloanservices.com. 86400 IN NS dns001.pnc.com.
agamerica.commloanservices.com. 86400 IN NS dns000.pnc.com.
agamerica.commloanservices.com. 3600 IN A 161.150.133.216
bin.agamerica.commloanservices.com. 30 IN CNAME gf2.agamerica.commloanservices.com.
gf1.agamerica.commloanservices.com. 3600 IN A 161.150.116.249
gf2.agamerica.commloanservices.com. 3600 IN A 161.150.40.249
agamerica.commloanservices.com. 3600 IN SOA dns001.pnc.com. hostmaster.pnc.com. 543792587 1200 180 1209600 600';
my $regex = qr/(?:
^
(?<host>[\w-]+\.[\w-.]*?)
\.\s*
(?<ttl>\d+)
\s*
(?<wtf>\w*)
\s*
(?<rectype>\w*)
\s*
(?<value>.*)
\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