I am setting up this example Perl snippet to validate for months in a date:
Some scenarios I want to accept are:
MM M
#!/usr/bin/perl
use str
Don't use regular expressions.
Perl has the ability to automatically evaluate as a number or a string based on context. 01-09 will evaluate to 1-9 in the numeric context. So, you can simply check for a value:
print "Enter in a month: ";
chomp($pattern = );
# We only want to print if the pattern matches
print "Pattern matches\n" if ($pattern < 13 && $pattern > 0);