Dan wrote: > > "John W. Krahn" <[EMAIL PROTECTED]> wrote in message > > > > You need to use the \b word boundary zero-width assertion. > > > > $variable =~ s/\b\Q$remove\E\b//g; > > Moving on, same subject/problem, but slightly different scenario.. > In my next variable $variable2, i have entries: > > $variable2 = "#ha #bad #cod #ba #dog"; > > Basically, i want to be able to remove #ba, without removing #ba from #bad, > so it ends up: > > $variable2 = "#ha #bad #cod #dog"; > > This also needs to be acheived without looping. I tried the method given for > the first scenario of $variable, but for some reason that solution doesn't > seem to be working for this.
The \b only works at the boundary between word (\w) and non-word (\W) characters and since # is not a word character this won't work. This will work but it will also remove the space in front of the match: s/(\s|^)#ba(?=\s|$)//; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]