in reply to Re^5: Use of uninitialized value in concatenation
in thread Use of uninitialized value in concatenation

Again, the following code, using a regex from postings elsewhere in this thread, always perfectly defines  $2 (although sometimes it is defined as the empty string – perfectly valid!) and seems to give the required output:
>perl -wMstrict -le "my %words = map { $_ => 1 } qw($Word $name $test); my $line = '$Word $ $ $ $test $testing'; $line =~ s/(\$(\w*))/exists $words{$1} ? $1 : qq{dollar$2}/eg; print qq{$line}; " $Word dollar dollar dollar $test dollartesting
Note that  (\$(\w*)) is the regex used.