my @in; while (<>) { push @in, $1 if /(\$[A-Za-z_]\w*)/; } #### while (<>) { push @in, /(\$[A-Za-z_]\w*)/g; } #### my %hsh; @hsh{@in} = (); print $_, $/ for keys %hsh; #### my %hsh; @hsh{ /(\$[A-Za-z_]\w*)/g } = () while <>; delete $hsh{''}; # tidy up print $_, $/ for keys %hsh;