## Original Python code. Normally I'd want to use a 'with' or something so the socket ## handler won't get leaked if I forget to write close or an exception bubbles up. def get(server, req=''): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((server, 70)) s.send(req + '\r\n') buff = '' while True: data = s.recv(1024) buff += data if data == '': break s.close() return buff ## Buggy Perl6 code I'm trying to write to do the same thing, but with ## a dynamic-unwind. sub get($host, $req) { my $sock = IO::Socket::INET.new(:$host, :$port(70)); $sock.print("\r\n"); my $buff = ''; loop { my $data = $sock.recv(1024); $buff ~= $data; break unless $buff; } $sock.close; $buff; }