in reply to Use of uninitialized value in concatenation

The regex expression  (\w+)? means "capture one or more word characters... or don't". This is the same as saying  (\w*): "capture zero or more word characters", and if zero characters are captured, you are left with an empty – but perfectly defined – string.
>perl -wMstrict -le "my %words = map { $_ => 1 } qw($Word $name); my $line = '$Word $'; $line =~ s/(\$(\w*))/exists $words{$1} ? $1 : qq{dollar$2}/eg; print $line; " $Word dollar