Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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

Wondering if anyone else if having an issue with perl 5.14 on ubuntu 12.04 when it comes to negating a character class in Perl.

Given the following small snippet

while(<>) {

    print if /[^Dd]an/;

With the following small input


I would expect


to be printed to the terminal instead I get Frank only.

Just wondering if anyone else was having a similar issue and figured out what the problem was. I'm going to search around for a bit and see if I can come up with anything I'll update if I find anything


share|improve this question
print if ! /[Dd]an/; – JJoao Oct 5 '15 at 16:59

The regular expression


Does indeed not match Steve. Basically, you're matching all lines with the sequence an, except those preceeding with a D or d. I don't see how you expect it to match Steve.

I think the behaviour is correct. Keep in mind that the negation is only applying to the characters within the [] section.

share|improve this answer

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.