my $line = "... can be found in s. 3 of the Interpretation Act. As Wilson J. clearly states..."; print "Before: $line\n"; $line =~ s/ s\. (\d+(\.\d+)?(\([^\)]+\))*) of( the)? (]+)\">)/ s\. $1<\/JL> of$4 $5/g; print " After: $line\n";