# Get a line from the user (or file if redirected) my $line = ; while ($line !~ /regex to check input/) { # input didn't match regex, so tell the user and get another line of data print "Sorry, I don't understand that, please enter the date like: DD-MM-YYYY\n"; $line = ; } ... code that uses properly formatted date ...