use strict;
my $str = '20141011T042032 - 14362918521340 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x06 EOT=0x0c Data=84 9f REPLY=4f c0 c0\\n
20200515T000132 4 2338257812 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x1c EOT=0x04 Data= 83 90 88 93 8b 98 88 90 REPLY= 3f
20200515T000132 4 2338257812 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x1c EOT=0x04 Data=REPLY= 3f
20200515T000140 12 2343757812 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x03 EOT=0x0C Data= 84 9c REPLY= 4c c0 c0
';
my $regex = qr/(?P<time>\d{8}T\d{6}) (?P<rti>.+) (?P<timestamp>\d+)\s?Bus=\s?(?P<bus>.*?)\s?C=\s?0x(?P<cmd>[0-9a-fA-F]{2})\s?S=\s?(?P<status>\w+)\s?RT=\s?(?P<rt>\d+)\s?RDI=\s?0x(?P<rdi>[0-9a-fA-F]{2})\s?EOT=\s?0x(?P<eot>[0-9a-fA-F]{2})\s?Data=\s?(?P<data>([0-9a-fA-F]{2}\s?)*)\s?REPLY=\s?(?P<reply>([0-9a-fA-F]{2}\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