in reply to Why won't $' work in a trinary operation?

To avoid this confusion, never use the trinary operator in a void context (when you have no intention of using the value returned). It's usually clearer to write it out, and avoids messy precedence issues like this. Remember that ?: is built so that it can be used in expressions as a replacement for a single value in a complex operation.

If all you're using it for is to control execution (make one assignment versus another), use a normal if/else construct:

if ($base_string =~ /^#/) { $foo = $'; } else { $bar = $base_string; }
Arguably using /^#(.*)/ and $1 instead of $' is going to be a bit more efficient. Generally it's best to shy away from $` and $', as these add costly operations to an otherwise straightforward regex match.