while($line = ) { $line =~ s{[^ -~]}{}g; # [^ -~] matches non printable ASCII chars print "$line\n"; # your new lines are gone after the above }