The idea is to look for spaces on word boundaries and remove them (i.e it monitors the transition of a word character into a non-word character and then removes the non-word character), you can also monitor the transition of a non-word character into a word character by detecting the word character boundary post a non-word character as in the second line.

$string = "H e l l o P e r l p r i n t"; print $string for $string =~ s/\b[ ]//g; print $string for $string =~ s/[ ]\b//g; UPDATE:added non-capturing square brackets to account for more efficie +ncy after Anomalous Monk's enlightenment...
An exercise question for you, what do you think the reason that running both the print lines above together would result in the following output, But running only a single line of either the two print statements works just fine?!
Hello PerlprintHelloPerlprint

Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

In reply to Re: help me ---regarding string by biohisham
in thread help me ---regarding string by perlprint

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.