sub unchomp { $_ = $_.$/ foreach @_ ? @_ : $_; } while (<$sock>) { chomp; # Don't want to transform the newline. s/([^[:print:]])/sprintf("\\x{%02X}", ord($1))/eg; unchomp; print; } #### sub unchomp { $_ = $_.$/ foreach @_ ? @_ : $_; } while (<$sock>) { chomp; # Don't want to transform the newline. s/([\x01-\x1F])/'^' . chr(ord('@')+ord($1))/ s/([^[:print:]])/sprintf("\\x{%02X}", ord($1))/eg; unchomp; print; }