use threads; ... async{ # Keep reading lines from the server. while (my $input = <$server>) { #save incoming information to database ... do this and that # Check errormessages and .... } };