use strict; use warnings; #Part one of the code, the wordlist is a file with one word per line and I transform this into a hash my $filename = "wordlist.txt"; open(INPUT, $filename) or die "Cannot open $filename"; my $line = ; while($line = ){ chomp($line); my @words = split(/\s+/, $line); my %unique = map {$_ => 1 } @words; my @unique = %unique; #part two of code, open the text file and extract words only (because the file also includes many numbers), and count the number of occurence stored in a hash open (DATA, "4.txt") or die; my @UnNum; my $x; my %dict; while () { chomp; $_ = lc; s/ -- / /g; s/ - / /g; s/ +/ /g; s/[.,:;?"!_()\[\]]//g; my @UnNum = split(/\s+/); foreach $x(@UnNum){ if ($x =~ /(([a-zA-Z']+-)*[a-zA-Z']+)/ ){ ++$dict{$x}; }}} #part 3 of the code, I try to compare the two different hashes and add the total number of occurrences while ((my $words,my $number) = each (%dict)) {my $total+= $number; if (exists($unique{$words})){ my $corresponding +=$number; print "There are $corresponding corresponding words of in total $total words";}} }