use strict;
my $str = '00:00.300 ID:4 zzzzzzzzzzz
00:02.155 ID:4 aaaaaaaaaaaaa
00:04.662 ID:4 dsadasd
**00:32.283** ID:4 level **790**
00:32.155 ID:4 Sfghgfs
00:32.200 ID:4 Tsdfsdfdfsff
**00:32.205** ID:4 level **640**
00:32.206 ID:4 Sadssd
00:32.208 ID:4 asdasgsfgsgsagsa
00:32.210 ID:4 adasgx
00:32.212 ID:4 Masddasdas.
**01:40:40.698** ID:4 level **500**';
my $regex = qr/((?:\d{2}:)?\d{2}:\d{2}\.\d{3})[^\n]+level[^\d]+(\d{3})/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