IO::Socket -> create the socket $sock->autoflush(1); $| = 1; while (<$sock> ){ if ($sock =~ /some stuff/){ do(some other stuff); } }