#!/usr/local/bin/perl use warnings; use strict; use Date::Simple; $|++; my $good_date = sub { my ($year,$month,$day) = ($1, $2, $3); my $date = do { no warnings 'uninitialized'; Date::Simple->new($year,$month,$day) }; return $date ? qr{(?=)} : qr{(?!)}; }; # CCYY-MM-DD[tz] my $pat = qr /^(\d\d\d\d)-(\d\d)-(\d\d)(??{$good_date->()})/; while () { chomp; print "$_ ", /$pat/ ? "matches\n" : "does not match\n"; } __DATA__ 1968-04-02 -0045-01-01 11968-04-02 1968-04-02+05:00 1968-04-02Z invalids to follow 68-04-02 1968-4-2 1968/04/02 04-02-1968 1968-04-31