Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a $cbDescription variable in a Perl script. When I print out $cbDescription, I get the following:

tIP SOLD -5 /ESH4 @1832.00

I want to remove any + or - or @ signs or commas from the string, so I have the following line:

$cbDescription =~ s/[+-\@,]//g;

I expect that line to change $cbDescription to:

tIP SOLD 5 /ESH4 1832.00

But when I print out $cbDescription after that line, I get:


Why did it also remove all the numbers and the decimal point?

share|improve this question
up vote 1 down vote accepted

- is a range delimiter in between brackets sou you need to escape it:

% echo "tIP SOLD -5 /ESH4 @1832.00" | perl -pi -e 's/[+\-\@,]//g'
tIP SOLD 5 /ESH4 1832.00
share|improve this answer
You can also specify it as the very first character in the class. – choroba Feb 16 '14 at 23:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.