use strict;
my $str = 'Jul 25 23:56:20 210.56.128.109 %PIX-6-302014: Teardown TCP connection 71946380 for Outside:203.117.152.202/80 to Corp-DMZ:proxy2/14266 duration 0:00:00 bytes 557 TCP FINs
Jul 25 23:56:20 210.56.128.109 %PIX-6-302014: Teardown TCP connection 71946381 for Corp-DMZ:proxy2/8080 to Internal:172.20.8.18/65181 duration 0:00:00 bytes 602 TCP FINs';
my $regex = qr/(?P<Timestamp>\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b[\s+\w+]+[\w+:?]+)\s+(?<SourceIP>[\d+\.?]+)\s+(?P<EventID>%PIX-6-\d+):\s+(?P<EventMessage>Teardown TCP connection\s+\d+) for (?P<OutsideIP>.*?) to (?P<InternalIP>.*?)\s+duration\s+(?P<Duration>.*?)\s+bytes(?P<Bytes>\s+\d+)\s+(?P<TCPstatus>.*)/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