I presume that your brackets cannot be nested? Because in your example strong, all the dollars are between brackets. (Note also that as is, we cannot deduce there are dollar signs in $line, as $10 and $s are two interpolated variables. But let's assume there's a lone q before the first double quote).
Assume that the above is true, and that all brackets are balanced, I'd write something like:
no warnings 'uninitialized';
$line =~ s/(<[^>]*>|\$[0-9])|\$/$1/g;
Alternatively, keep the warning, replace the replacement with $1 || ""
and use /e
to eval the replacement.