use strict;
use warnings;
use IO::Socket;

my $sock = new IO::Socket::INET(
									PeerAddr=> 'localhost',
									PeerPort=> '7070',
									Proto => 'tcp');

die "Could not create socket: $!\n" unless $sock;

my $run = "yes";
while($run eq "yes")
{

my $text = <STDIN>;
print $sock "$text";
print "Send more strings? yes/no";
$run = <STDIN>;
}
close($sock);

i have an while loop so that the script keeps running and you can enter text again for sending but i wont work why?

Your loop runs while($run eq "yes") but when the user enters yes at the prompt then $run contains yes with a newline character at the end. Try doing a chomp on the $run after assigning the STDIN to it.

print "Send more strings? yes/no";
$run = <STDIN>;
chomp($run);#Remove the newline character from input
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.