se DateTime::Format::Strptime; my $dt_format = DateTime::Format::Strptime->new(pattern => "%d-%m-%Y"); sub val_date { my $dt = shift; $dt =~ s|[./]|-|g; # '.' and '/' become '-' for simplicity return $dt_format->parse_datetime($dt); } my $s = '01-02-2007'; my $dt = val_date($s); if ($dt) { print "valid date\n"; } else { print "not a date\n"; }