in reply to substition problem

Why not try:
s/(?<!\\)(\$[a-zA-Z0-9_]+)/change_name($1)/ge;
(note, using the placeholder around the variable name at this point, so that what matches should fall into $1).
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain