use constant REGEX => qr/^(\d{4})-(\d{2})-(\d{2})/; while (<>) { chomp; printf "$_: match=%s\n", ($_ =~ m{(??{REGEX})} ? 1 : 0); }