use Date::Calc qw(check_date check_time); our $DEBUG = 1; # set to 0 to disable print "woohoo!\n" if valid( ['033103','12:59'] ); # March 31, 2003 12:59 valid print "w00t!\n" if valid( ['022803','13:00'] ); # February 28, 2003 13:00 valid print "Yippee!\n" if valid( ['023103','08:40'] ); # February 31, 2003 8:40 invalid sub valid { my $ref = shift; my $date = shift @$ref; my $time = shift @$ref; die "Invalid date format $date" unless $date =~ /(\d\d)(\d\d)(\d\d)/; my ($month, $day, $year) = ($1, $2, $3); $year += ($year <= 69) ? 2000 : 1900; die "Invalid date $date" unless (check_date($year,$month,$day)); die "Invalid time format $time" unless $time =~ /(\d\d):(\d\d)/; my ($hour, $minute) = ($1, $2); die "Invalid time $time" unless (check_time($hour,$min,$sec)); print "$date $time is valid.\n" if $DEBUG; return 1; }