in reply to reg ex NOT

In addition to using the "complement character class" notation in the first suggestion above, there is also a thing called a "zero-width negative look-ahead assertion". (A bunch of "zero-width assertions", as well as character classes and everything else, are described in helpful detail in the perlre man page.)

Note the following subtle difference between using a character-class vs. using a zero-width assertion:

#!/usr/bin/perl use strict; my $string1 = "don"; # should both of these match? my $string2 = "donk"; # (you be the judge, and choose # your regex accordingly) my %regex = ( complem_char_class => qr/don[^t]/, zwid_neg_lookahead => qr/don(?!t)/, ); for my $regtyp ( sort keys %regex ) { print "\n"; for ( $string1, $string2 ) { my $result = ( /$regex{$regtyp}/ ) ? "succeeds" : "fails"; print "For $_ : match $result based on $regtyp\n"; } }
The output of that little snippet shows that the character-class regex has to match something (that is, there has to be a character in that position, and the character can be anything other than "t"), so the string "don" (with nothing after "n") won't match.

The "zero-width" operators allow you to state some condition that needs to be satisfied at a given position in the string, whether or not there happens to be a character present at that position.