in reply to problem with substitution regex

You need to use a negative lookahead assertion. From perlre:
(?!pattern) A zero-width negative lookahead assertion. For example /foo(?!bar)/ ma +tches any occurrence of ``foo'' that isn't followed by ``bar''.
However, you can't just add (?!\[) because it will backtrack and match only part of the variable. So to ensure that it will only match the whole variable and not part, add a \b (word boundary): s/(?<!\\)(\$[a-zA-Z0-9_]+)\b(?!\[)/whatever()/ge;