if ( $str =~ /[^\x09\x0A\x0D\x20-\x7E]/g ){ print "Contains invalid characters"; }