#!/usr/bin/perl -w use strict ; use warnings; for my $d qw(2005-12 2005-100 2005-1- 2005-12- 2005-123- 2005-1000) { printf "%-10s: ", $d; if ( $d =~ /\d{4}-\d{1,3}([^-\d]|$)/ ) { print "yep\n" ; } else { print "nope\n"; } } #### 2005-12 : yep 2005-100 : yep 2005-1- : nope 2005-12- : nope 2005-123- : nope 2005-1000 : nope