If I understand your question and your use of the word "tokenize" correctly, you just need a regex where all names are ORed.

The regex engine is already trie optimized.

updated

now that I'm back to a desktop computer let's try...

DB<105> %names =( '&#32431;&#12385;&#12419;&#12435;' => 2, '&#21608;&#26480;&#20523;' => 57, 'Alex Fong' => 100, ) DB<106> $input=q{"Esther Kwan, &#32431;&#12385;&#12419;&#12435; | Al +ex Fong (Hong Kong) / Joe Smith ; Fong &#21608;&#26480;&#20523; Feren +c Kállai"} DB<107> $regex = join '|', keys %names DB<108> @matches = ( $input =~ /($regex)/g ) DB<110> print join ",", @matches &#32431;&#12385;&#12419;&#12435;,Alex Fong,&#21608;&#26480;&#20523;

here pre formated to display unicodes characters...

  DB<105> %names =(
           '纯ちゃん' => 2,
           '周杰倫' => 57,
           Alex Fong => 100,
           )

DB<106> $input=q{"Esther Kwan, 纯ちゃん | Alex Fong (Hong Kong) / Joe Smith ; Fong 周杰倫 Ferenc Kállai"}

DB<107> $regex = join '|', keys %names

DB<108> @matches = ( $input =~ /($regex)/g )

DB<110> print join ",", @matches 纯ちゃん,Alex Fong,周杰倫

update

reading your task description again I doubt that your teacher will accept this approach as homework! =)

Cheers Rolf

( addicted to the Perl Programming Language)


In reply to Re: How to tokenize string by custom dictionary? (+code) by LanX
in thread How to tokenize string by custom dictionary? by infantcoder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.