my $string = "\x07\x1b\x04Safe \x12to print\x03.\n"; $string =~ s/\P{Print}//g; print $string if length $string;