unless ( ( $display =~ /^[\w-]+$/ ) # Can contain chars, digits, _ and - && ( $display !~ /^\d+$/ ) # But not just digits ) { # String failed to validate. }