perlfaq nodetype
faq_monk
<P>
Two common misconceptions are that <CODE>␈</CODE> is a synonym for [perlman:perlop|s+], and that it's the edge between whitespace characters and non-whitespace
characters. Neither is correct. <CODE>␈</CODE> is the place between a <CODE>w</CODE>
character and a <CODE>W</CODE> character (that is, <CODE>␈</CODE> is the edge of a ``word''). It's a zero-width assertion, just like <CODE>^</CODE>, <CODE>$</CODE>, and all the other anchors, so it doesn't consume any characters. [perlman:perlre|the perlre manpage]
describes the behaviour of all the regexp metacharacters.
<P>
Here are examples of the incorrect application of <CODE>␈</CODE>, with fixes:
<P>
<PRE> "two words" =~ /(w+)␈(w+)/; # WRONG
"two words" =~ /(w+)s+(w+)/; # right
</PRE>
<P>
<PRE> " =matchless= text" =~ /␈=(w+)=␈/; # WRONG
" =matchless= text" =~ /=(w+)=/; # right
</PRE>
<P>
Although they may not do what you thought they did, <CODE>␈</CODE> and <CODE>B</CODE>
can still be quite useful. For an example of the correct use of
<CODE>␈</CODE>, see the example of matching duplicate words over multiple lines.
<P>
An example of using <CODE>B</CODE> is the pattern <CODE>BisB</CODE>. This will find occurrences of ``is'' on the insides of words only, as in
``thistle'', but not ``this'' or ``island''.
<P>