I think it is just the trailing space in the pattern which is tripping you. I tried:
#!/usr/bin/perl
use strict;
my $lamb = 'wolf';
my $text = 'Mary had a little $lamb.';
$text =~ s/(\$\w+)/$1/eeg;
print $text . "\n";
# output: Mary had a little wolf.