The problem has nothing to do with word boundaries. The problem is that you're replacing your replacements. Fix:
my $pat = join '|', keys(%hashstore); $doc =~ s!\b($pat)\b!$1/$hashstore{uc($1)}!ig;

You're wrong about the negative lookbehind not working.

my %hashstore = ( "DEXX" => "AREX", "AREX" => "CUBE" ); my $doc1 = "DEXX"; my $doc2 = "DEXX"; my $doc3 = "DEXX"; #foreach (keys %hashstore){ foreach ("DEXX", "AREX"){ # Make sure we get them in the worse order. $doc1=~s#\b($_)\b#$1/$hashstore{uc($_)}#ig; } #foreach (keys %hashstore){ foreach ("DEXX", "AREX"){ # Make sure we get them in the worse order. $doc2=~s#(?<!/)\b($_)\b#$1/$hashstore{uc($_)}#ig; } my $pat = join '|', keys(%hashstore); $doc3 =~ s!\b($pat)\b!$1/$hashstore{uc($1)}!ig; print("$doc1\n"); # DEXX/AREX/CUBE print("$doc2\n"); # DEXX/AREX print("$doc3\n"); # DEXX/AREX

Note the addition of uc(). Without it, you'd match stuff you wouldn't find in the hash because of /i.


In reply to Re: Getting around "/" as a word boundary by ikegami
in thread Getting around "/" as a word boundary by sherab

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.