my $keywords = q|fait une petite St-Laurent|; my @keywords = split / /, $keywords; $text =~ s|\s*.*?||g; #remove all the citations $text =~ s|<|<|g; $text =~ s|>|>|g; $text =~ s|<\s*.*?>||g; #remove any html $text =~ s|\[\s*.*?\]||g; #remove any bbcode tags my $strings; use Data::Dumper; my @split = split / /, $text; my $number = 0; my $hash_count = 0; foreach (@split) { $back .= "$_ "; if (length($back) >= 250) { # print qq|Adding to: \$string->{$number} \n|; $strings->{$number}->{value} = $back; $strings->{$number}->{count} = get_word_count_match($back); $back = undef; $number++; } } print Dumper($strings); sub get_word_count_match { my $text = $_[0]; my $total_words_found; foreach (@keywords) { my $count =0; $count++ while $text =~ /\Q$_/g; $total_words_found = $total_words_found + $count; } return $total_words_found || 0 ; }