http://www.perlmonks.org?node_id=1046486


in reply to remove spaces after join operation

Not sure this is exactly what you're looking for, but:
print join(' ',@first_sentence) =~ s/\s*([.()])\s*/$1/gr;
Prints:
i am 2(but).how

Replies are listed 'Best First'.
Re^2: remove spaces after join operation
by lakssreedhar (Acolyte) on Jul 26, 2013 at 11:27 UTC

    This error Can't modify join or string in substitution (s///) at out.pl line 5, near "s/\s*(\.\(\))\s*/$1/g;" is being shown

      Ah, is your version of Perl too old to support the /r modifier? It wont work without it. I Suppose:
      my $txt = join ' ',@first_sentence; $txt =~ s/\s*([.()])\s*/$1/g; print $txt;
      Updated to simplify regex as suggested by hdb

        ya its working now