$test_date = "12-02-2001"; if ($test_date =~ s/^([0-1]?\d)\-([0-3]?\d)\-([0-9]{4})$/$3\-$1\-$2/) { print $test_date; } else { print "boom"; }