use strict;
my $str = '2014-03-27 12:39:32 20 10.71.15.207 304 TCP_HIT 367 1470 GET http www.computerworld.com 80 /elqNow/elqFCS.js - - - - 23.196.74.53 application/x-javascript http://www.computerworld.com/s/article/9247206/Gameover_malware_takes_aim_at_Monster.com_and_CareerBuilder.com "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)" OBSERVED "Technology/Internet" - 163.252.254.201 23.44.202.53 52809
';
my $regex = qr/(?<date>\d+\-\d+\-\d+).(?<time>\d+:\d+:\d+).(?<timetaken>\d+).(?<cip>\d+\.\d+\.\d+\.\d+).(?<scstatus>\d+).(?<scaction>\S+).(?<scbytes>\d+).(?<csbytes>\d+).(?<csmethod>\S+).(?<csurischeme>\S+).(?<cshost>\S+).(?<csuriport>\d+).(?<csuripath>\S+).(?<csuriquery>\S+).(?<csusername>\S+).(?<csauthgroup>\S+).(?<shierarchy>\S+).(?<ssuppliername>\S+).(?<rscontenttype>\S+).(?<csreferer>\S+)."?(?<cs_user_agent>.+)"?./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