in reply to Use of uninitialized value in concatenation

Your code will never assign a value to $2.
If I understand correctly you want to change to $ to a literal "dollar" if the string after it is not a key of the hash.?
$line =~ s/(\$)(\w+)?/$2 ne ""?(exists $words{$2} ? "$1$2" : "dollar$2 +"):"dollar"/eg;