If I have a multiline text like.. abcd ef ghi xyz d e f d sjskf s fdf then how would I be able to remove the spaces (/s+) inside the strings (in middle of the strings). I thought using doing like... $string =~ s/\s+/ /g; would work. but it does not work. And if above is the way I would end up finally then can I make it like so it would not alter spaces within <pre> tags like.... #declaring pretags avlyes my $startPreTag="<pre>"; my $endPreTag="</pre>"; #so the spaces (more than one) will be removed is it is not enclosed by pre tags $string =~ s/[^$startPreTag]^\s+[^$endPreTag]//; Please tell me if I am on the right track None of my appraoches are working. Please advise. Thanks!