in reply to Re^2: IO::Socket and passed variables to functions
in thread IO::Socket and passed variables to functions

should have produced an output of START~CIC~END but it did not...it printed something like ENDsCIC

Looks like the typical sign of a stray carriage return (\r), i.e. the print cursor is re-positioned to the beginning of the line, with initial text thus being overprinted by subsequent characters...  For example

my $grp = "CIC\r"; print "START~" . $grp . "~END\n";

would show the seemingly weird "~ENDT~CIC".

Have you tried what oshalla suggested, i.e. $buf =~ s/\s+$// instead of chomp?  It should fix such CRLF issues.