in reply to help me ---regarding string

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.

Replies are listed 'Best First'.
Re^2: help me ---regarding string
by AnomalousMonk (Archbishop) on Oct 06, 2009 at 10:20 UTC
    Although perlprint asked only about blanks and letters, sometimes punctuation creeps in. The third alternative handles all non-blanks and avoids capturing:
    >perl -wMstrict -le "my $string = 'W h a t H o ? N o G o .'; (my $sqz1 = $string) =~ s{ [ ] \b }{}xmsg; print qq{'$sqz1'}; (my $sqz2 = $string) =~ s{ \b [ ] }{}xmsg; print qq{'$sqz2'}; (my $sqz3 = $string) =~ s{ [ ] (?![ ]) }{}xmsg; print qq{'$sqz3'}; " 'What Ho ? No Go .' 'What Ho? No Go.' 'What Ho? No Go.'
    Update:  (?![ ]) vice  (?=\S) in third example.