my $buffer; while (my $line = $socket->getline()) { # Maybe this is the "END" line, and if it is, # bail out of the loop because we're done! last if ($line =~ /^END$/); # Otherwise, just tack that stuff onto the buffer. $buffer .= $line; } print "Read: ", $buffer, "\n";