use strict;
my $str = '<Idle,MPos:0.000,0.000,0.000,WPos:0.000,0.000,0.000,Buf:8,Ln:49,Lim:1001>
<Run,MPos:4.028,0.000,0.000,WPos:4.028,0.000,0.000,RX:25,F:34.4>';
my $regex = qr/<(?'State'Idle|Run|Hold|Home|Alarm|Check|Door)(?:,MPos:(?'MX'[0-9\.]*),(?'MY'[0-9\.]*),(?'MZ'[0-9\.]*))?(?:,WPos:(?'WX'[0-9\.]*),(?'WY'[0-9\.]*),(?'WZ'[0-9\.]*))?(?:,Buf:(?'Buf'[0-9]*))?(?:,RX:(?'RX'[0-9]*))?(?:,Ln:(?'L'[0-9]*))?(?:,F:(?'F'[0-9\.]*))?(?:,Lim:(?'Lim'[0-1]*))?(?:,Ctl:(?'Ctl'[0-1]*))?>/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