#!/usr/bin/perl -wl use strict; use IO::Socket::INET; my $sock = IO::Socket::INET->new("localhost:12345") or die $!; my $buf; while ($sock->read($buf, 4)) { # get count my $count = unpack "N", $buf; $sock->read($buf, $count*4); # read actual data my @data = unpack "N$count", $buf; print "$count: @data"; } close $sock;