while (!(recv $connection,$z,1000,0)){}; #The following line prints the correct number of packets #fetched print "\nLength fetched: ",length($z)," string ",$z if length($z); my $g=0; #$z=quotemeta $z; #This while exits *before* it has finished the string while (my $a=substr $z,$g,1) { $g++; #Process characters in this here