\b is true at a word boundary whereas \B is true when not at a word boundary. Here is an example that does as you want and demonstrates the difference.
$_ = '*that old time* music *kinda soothes* my soul'; s{ # sub ( # capture in $1 (\B[^\w\s]\b) # capture token in $2 at boundary [^\2]+? # 1 or more non tokens (minimum of) \b\2\B # matching token at boundary ) # close capture $1 } # close the first part of the regex # now generate the substitution pattern { $fnd = $1; # store what we have found $tok = $2; # this is our token to add $fnd =~ s/ # now modify $fnd (\w) # find a letter -> $1 (\s+) # space(s) -> $2 (\w) # another letter-> $3 # now add the tokens we want /$1$tok$2$tok$3/xg; $fnd # $fnd will now get substituted into our string }gex; print;
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: Y.A.R.M.
by tachyon
in thread Y.A.R.M.
by Intrepid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |