use strict; use warnings; my $fmt; print map { sprintf qq{Date: %-12sFormat: %-s\n}, $_->[0], $_->[1] } map { $fmt = q{Date not valid}; m{(?x) ^\d\d(\D)\d\d(\D)\d{4}$ (?{$fmt = qq{DD${1}MM${2}YYYY}}) }; m{(?x) ^\d{4}(\D)\d\d(\D)\d\d$ (?{$fmt = qq{YYYY${1}MM${2}DD}}) }; m{(?x) ^\d\d(\D)\d\d(\D)\d\d$ (?{$fmt = qq{DD${1}MM${2}RR}}) }; [$_, $fmt]; } map {chomp; $_;} ; __END__ 99/99/9999 99/99/99 99-99-9999 99-99-99 99-99 99-99-999 99:99:9999 99:99:99 99+99+9999 9999-99-99 9999:99:99 9/99/99 9999+99+99 99-99.9999 99.99-9999