in reply to Regex Pattern Problem

How about simply adding the $ anchor to your current regex? (5 or more digits and then the end of the string):

unless ($num =~ /^\d{5,}$/) { # and more generally to combine a couple of conditions: unless ($num =~ /^\d{5,}/ and $num !~ /\D/) {