#!/usr/bin/perl -w use strict; use Date::Calc qw(check_date); my $datestring = shift or die "$0: please pass a date string as the first argument\n"; if ( $datestring =~ m|^\s*(\d{2})\D*(\d{2})\D*(\d{4})\s*$| # ^ : starting at the beginning # \s* : skip any initial spaces, # (\d{2}) : get two digits (and save them... first save is $1), # \D* : skip any non-digits, # (\d{2}) : get another two digits (and save them... second save is $2), # \D* : skip any non-digits, # (\d{4}) : get another four digits (and save them... third save is $3), # \s* skip any ending space # $ : make sure you're at the end of the string and check_date($3, $1, $2) # $3=year, $1=month, $2=day ) { print "valid date: $3/$1/$2\n"; } else { print "invalid date\n"; }