In answerTelnetOpts(), the code to extract the subcommand from the data
stream isn't quite right: it is currently
my $subcmd = substr($data, $pos + 2, $endpos - $pos + 1);
Which can leave up to two unwanted characters at the end of the subcommand.
It should be
my $subcmd = substr($data, $pos + 2, $endpos - ($pos + 2) + 1);
or equivalently
my $subcmd = substr($data, $pos + 2, $endpos - $pos - 1);