use strict;
my $str = '<span class="sense"><span class="bld">A</span> [[lay bare at the side]], [[expose]], τι τῆς πλευρᾶς <span class="bibl">Arr. <span class="title">Tact.</span>40.5</span>, cf. <span class="bibl">D.C.49.6</span> (Pass.). </span><span class="sense"><span class="bld">2</span> metaph., [[lay bare]], [[disclose]], τὸν πάντα λόγον <span class="bibl">Hdt.1.126</span>, cf. <span class="bibl">8.19</span>, <span class="bibl">9.44</span>; τὸ βούλευμα <span class="bibl">Conon 50</span>:—Pass., <b class="b3">παρεγυμνώθη διότι</b>… <span class="bibl">Plb.1.80.9</span>.</span>
<span class="sense"><span class="bld">A</span> [[lay bare at the side]], [[expose]], τι τῆς πλευρᾶς <span class="bibl">Arr. <span class="title">Tact.</span>40.5</span>, cf. <span class="bibl">D.C.49.6</span> (Pass.).';
my $regex = qr~<span class="sense"><span class="bld">A<\/span>(?s)(?!.*<span class="bld">)~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