use strict; use warnings; use utf8::all; my $listfile = "list.txt"; open IN, '<', $listfile or die "could not open $listfile"; binmode(IN, ":utf8"); open OUT, '>', "result.txt" or die "could not open out"; binmode(OUT, ":utf8"); my %count; my @lists = (); while (my $line1 = ) { chomp (my $key1 = (split /\t/, $line1)[0]); push(@lists,$key1); } close IN; foreach my $list (@lists) { $count{$list} = 0; } my $textfile = "textfile.txt"; open my $fh, '<', $textfile or die "Could not open '$textfile' $!"; while (my $line = <$fh>) { chomp $line; foreach my $mot (keys (%count)) { chomp $mot; foreach my $str ($line =~ /$mot/g) { $count{$str}++; } } } foreach my $word (reverse sort { $count{$a} <=> $count{$b} } keys %count) { print OUT "$word\t$count{$word}\n"; }