Perl loop txt and check if a hash key

Hi,
The task i have to do is to
1- create a database contains the Names .run the query and store results in hash make the Name field is the hash key
2- in the same time i have a txt which i will loop through it word by word and check for each word if a hash key ( compare it with the Names in the Name field in the hash ) or not if it is a key print it to a txt file and print that it match the database.

Now , the code can get the results from db in a hash form with the key field Name andin the same time loop through the input txt word by word

But till now i can't compare these words withthee names stored in the hash to know if it match or not.

I am abeginner and really i arrive to this level after alot of efforts and i can't go ahead with code any more. So really i need your help.

#!/usr/bin/perl
use DBI;
 
               #step1
  $sqlstatement = "select Name from protiens;";
     #open connection to Access database  
   $dbh = DBI->connect('dbi:ODBC:driver=microsoft access driver (*.mdb);dbq=C:\protiens.mdb') ;
      #prepare and execute SQL statement 
$sth = $dbh->prepare ($sqlstatement);
$sth->execute || die "Could not execute ";
$ref1 = $sth->fetchrow_hashref($Name);
while($ref1 = $sth->fetchrow_hashref($Name)){
print "$$ref1{'Name'}\n";
}
 
           # step2
%hash1 = $$ref1{'Name'};
if(exists $hash1{$key}){
print "there is a key\n";
}
 
            #step3
$filename= 'C:\project\abstract of protein.txt';
open (FILE,$filename) or die $!;
while (<FILE>){
  for $word (split)
  { 
      # define hash
%hash2 = $word;
foreach $key (%hash2) {
      #Check for a hash key
if(exists $hash2{$key}){
print "there is a one key\n";
}
}
 
 }        #step4 unknown
   if ($ref1{$key} eq $hash2) {
       print "The key for $hash2 is $key\n";
          $flag++;
                               }
 
         unless ($flag) {
           print "There is no key for $hash2".\n;
                         }
}