Re: Negate a regular expression



!~ will return true if the thing on the right does not match.
In your case, however, using unless seems more logical. Something like

exit unless (lc($answer) =~ /^[y|yes]$/)

should work. The ^ and $ are there to make sure that the string
contains nothing but ``y'' or ``yes''. Make sure that you do
chomp($answer) before running this, though, because the newline
character may break it.
.