use POSIX; for ("foo; is ok", "foo\x3") { if (/[^[:print:]]/) { print "Contains unprintables\n"; } else { print "$_ is safe\n"; } }