use strict;
my $str = '2015-05-13T23:39:43.945958Z my-loadbalancer 192.168.131.39:2817 10.0.0.1:80 0.000086 0.001048 0.001337 200 200 0 57 "GET https://www.example.com:443/ HTTP/1.1" "curl/7.38.0" DHE-RSA-AES128-SHA TLSv1.2
2015-05-13T23:39:43.945958Z my-loadbalancer 192.168.131.39:2817 10.0.0.1:80 0.001069 0.000028 0.000041 - - 82 305 "- - - " "-" - -
2015-05-13T23:39:43.945958Z my-loadbalancer 192.168.131.39:2817 10.0.0.1:80 0.001065 0.000015 0.000023 - - 57 502 "- - - " "-" ECDHE-ECDSA-AES128-GCM-SHA256 TLSv1.2';
my $regex = qr/^(?P<clb_timestamp>[^\s]+)\s*(?P<clb_elb>[^\s]+)\s*(?P<clb_client_addr>[^:]+):\s*(?P<clb_client_port>[^\s]+)\s*(?P<clb_target_addr>[^:]+):\s*(?P<clb_target_port>[^\s]+)\s*(?P<clb_request_processing_time>[^\s]+)\s*(?P<clb_backend_processing_time>[^\s]+)\s*(?P<clb_response_processing_time>[^\s]+)\s*(?P<clb_elb_status_code>[^\s]+)\s*(?P<clb_backend_status_code>[^\s]+)\s*(?P<clb_received_bytes>[^\s]+)\s*(?P<clb_sent_bytes>[^\s]+)\s*"(?P<clb_request>[^\"]+)"\s*(?P<clb_user_agent>[^\s]+)\s*(?P<clb_ssl_cipher>[^\s]+)\s*(?P<clb_ssl_protocol>[^\s]+)/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