sub slow_match { my($hash_ref_1,$hash_ref_2) = @_; while ( my($pattern,$high_lvl_id) = each(%hash1) ) { my $match = qr/\b$pattern\b/; while ( my($text_id,$text) = each(%hash2) ) { if ($text =~ $match) { $$hash_ref_1{$text_id} .= ':'.$high_lvl_id; foreach my $part (split(/\s/,$pattern)) { $$hash_ref_2{$text_id} -> {$part} = 0; } } } } }