use strict;
my $str = '[P1/1]0(4)0(5)**[P1/432]** g(5)I(2)d(7)a(8)`<em>`b(5)[P1/4]C(6)e(7)B(8)B`</em>`(9)[P1/5]0(6)i(7)[P1/6]0(1)I(2)[P1/7]0(6)[P1/1]0(1)0(2)[P1/2]E(1)c(2)d(3)a(4)**[P1/3]** 0(1)`<em>`b(2)[P1/4]C(1)e(2)B(3)B`</em>`(4)[P1/5]0(1)
';
my $regex = qr@\[[^\]\[]*\](?=[^\]\[]*<em>)@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