If you are using values entered from <STDIN> don't forget to chomp($value) the value. This will remove a newline character (if it exists). A newline character at the end of $value in your example would cause it to fail the regex as well as the above noted problems.