Do $datastring and/or $password maybe contain:
- A character with ASCII value 255? That's the telnet IAC character...if you pass it to $telnet->print(), Net::Telnet will escape it with an extra IAC character. If the other end isn't actually doing the telnet protocol, it won't strip out the extra character.
- A carriage return that is NOT followed by a newline? Net::Telnet will add a NULL char (ASCII 0) after the carriage return
In short, if the other end isn't really speaking true "telnet", it can cause this sort of thing.
You could try $telnet->telnetmode(0); ... that turns this behavior off, making it more like a plain socket.