while (my $text=<$testo>){
for my $key (keys %hash){
my $value = $hash{$key};
my $arrkey=$key." ";
my $count = 0;
$count += () = /\b$key\b/ig while <>;
print $conteggio "$arrkey) => $count\n";
} ;
} ;
reads the file line by line into $text, and then tries each column 1 word (captured earlier as the key values in your %hash). The regex /\b$key\b/ig is plausible, and the [oi] stuff will do what you want -- the [Nn] will also work, but are redundant because of the i qualifier of the regex.
The rest is, frankly, a dogs breakfast and can be thrown away.
To count the number of times you get a match in each line, my $count = () = $text =~ /\b$key\b/ig ;
is sufficient, but fairly deep magic. This: my $count = 0 ; while ($text =~ /\b$key\b/ig) { $count++ ; } ;
may or may not seem clearer.
Now your problem is how to collect the count for each word across all the lines of your input. I suggest using the value part of your hash entries to hold the count for the word in the key part.
When the while loop has finished, your hash should contain the count for each word, which you can then output to $coteggio.
|