chomp $d; if($d =~ m/^\d{6}$/) { ### use ^ and $ for start and end print "Exact match\n"; } else { print "Not Correct\n"; }