my $sock; $sock = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port, Proto => 'tcp'); open (FILEOUT,">output.log"); my @msgstream; while (<$sock>) { #process line until end of socket stream my $line=$_; if ($line=~/^;/) { # if the line has a ';' in it processmsg(\@msgstream); undef @msgstream; #clear @msgstream } else { # add to msgqueue push @msgstream,$line; } }