use warnings; use strict; while(<>) { for my $char (split '') { my $ord = ord($char); print $ord > 31 && $ord < 128 ? $char : '?' } }