use strict;
my $str = 'Jul 14 06:03:92 jhyhr0392 postfix/postdrop[9303]: **warning: unable to lookup public/pickup: Nosuch file or directory**
Jul 14 06:03:92 jhyhr0392 sendmail[9303]: 09AX982X4GT36: to=root, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=53002, relay=[127.0.0.1] [127.0.0.1],dsn=4.0.0, state=Deferred: Connection refuse by [127.0.0.1]';
my $regex = qr/(?P<timestamp>\w+\s\d+\s\d+:\d+:\d+)\s(?P<host>\w+)\s(?P<process>\w+\/\w+|\w+)\[(?P<process_id>\d+)\]\W+(?P<message_id>\d+[a-zA-Z0-9]+)?.+:(?P<message>.*)/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