use strict;
my $str = 'L 065 00 24329 12313 244.0.15.55 252.9.11.90 02/25 08:05 00:00:44 0000 0000
N 066 00 23442 T000185 262.1.00.09 02/25 08:05 00:00:02 A 16630
& 0000 0000
S 067 00 00984 T000134 02/25 08:06 00:00:02 A 61445
& 0000 0000
S 068 00 T000002 29536 02/25 08:05 00:00:36
& 0000 0000 1234567890XXXXXX
E 069 00 T000002 T000185 02/25 08:06 00:00:00
& 0000 0000 1234567890XXXXXX
L 065 00 24329 12313 244.0.15.55 252.9.11.90 02/25 08:05 00:00:44 0000 0000 ';
my $regex = qr/^[LNSE] .*(?:\n(?![LNSE] ).*)?/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