for my $str ( "\x7f", "asdf", "asdf\x8f", "\x8f" ) { print "$str contans ", ( $str =~ tr/\0-\x7f//c ) ? "non-" : "only ", "ascii.\n"; }