in reply to Pack hex string and send to socket

You should remove spaces from the $hexcommand before running pack on it:
$hexcommand =~ s/ //g;
Printing to socket should be ok, but consult the protocol documentation on when to print.