It isn't working for a multiplicity of reasons. First off, your regex is capturing nothing in $1, so you shouldn't be using that var. In same regex, your ^ is misused - ^ should be placed so that it anchors the front of the line - it cannot be preceeded by \b and be sanely used. Your push of @in is unconditional, which is also wrong - you only want to push if the regex matches. Further, you should be using a hash to collect uniq values, not an array. I don't even begin to understand what that grep is trying to do.
This code should be a good start...
#!/usr/bin/perl
use Data::Dumper;
while (<DATA>) {
$in{$1} = 1 if ($_ =~ (/^\s*(\$\w+.*)/));
}
@a = keys %in;
print Dumper \@a;
__DATA__
$first = 1;
$first = 1;
$second = 2; #some comment
# $third = 3;
Please also read this link Perl Idioms Explained - keys %{{map{$_=>1}@list}}.