in reply to IO::Socket and Term::Readline

The following line is using $OUT, which is not declared anywhere:

print $OUT $res, "\n" unless $@;

The \n is ignored here, and that comma should probably be a concat operator:

$res = eval($_), "\n";

Both of these were found by use strict, and the -w flag on the shebang. Please use it. The program then runs, or at least runs well enough to begin the real debugging.