my (@cmds) = ("HELO", "dom:$domain", "ipaddr:$ipaddress", "addzone"); while (@cmds) { print $ns1 shift(@cmds), "\n"; $line = <$ns1>; # don't need the sleep; # the read should block until # a line is available. defined($line) or last; # quit if connection closed # (could die instead) print $line; # don't need \n now, $line # not chomped ($line =~ /^CAIO$/) and last; # $ can handle trailing # newline, with no # significant speed penalty # (should be optimized by # regex engine) }