while my $text=<$testo>){ ... $count += () = /\b$key\b/ig while <>; }