Tybalt has the right fix, but I think some additional commentary might help.
Socket programming can be bit messy. When you read, sometimes you get a partial message, and sometimes you get more than one message. You code will need to read a chunk of data, then find out how many whole messages you got, then process each of them, then hold onto any leftover fragment to be combined with the next read. This needs tracked per-connection. When you ask perl to read a line with <FILEHANDLE> perl will keep reading until it sees an end-of-line. If you have a blocking file handle, this stalls your whole program. But, if you change to non-blocking file handles, perl will think it reached end-of-file and return the fragment even if it isn't a whole line. The second one is a useful behavior, but sysread() is generally a better approach, since it keeps you closer to the native Unix interface (and you need most of that to write a sockets program correctly).
While doing this is a good learning exercise, and might be sort of a required first step to fully understand sockets, for "getting things done" I recommend an event-driven framework like AnyEvent or IO::Async ecosystem. (Check out AnyEvent:Handle ) These frameworks take care of lots of socket details for you and let you focus on the interesting parts of the program.