Let's say I'd like to remove a space after every word. In reality, the regular expression before the space is more complex.
$text =~ s/(\w+) /$1/g;
works as expected, but I don't like the need for the $1, because it doesn't seem to be very efficient to match something, remove it and insert it again. I tried a positive lookahead, but this doesn't work:
$text =~ s/(?=\w+) //g;
I understand that it doesn't work because the "position" does not change with this lookahead. Is there another way to get rid of the $1?