use IO::File; use IO::Socket; use IO::Select; my $file = '/tmp/test_file'; my $sel = IO::Select->new; my $pos = -s $file; my $fh = IO::File->new; # read the file a first time if you like . . . # Add IO::Socket objects to $sel if ($pos < -s $file) { $fh->open($file, 'r') or die $!; $fh->seek($pos, 0); $sel->add($fh); } { my @ready = $sel->can_read; for (@ready) { if ($_ eq $fh) { print <$fh>; $sel->remove($fh); $pos = $fh->tell; $fh->close(); } else { # do socket things } } if ($pos < -s $file) { $fh->open($file, 'r') or die $!; $fh->seek($pos, 0); $sel->add($fh); } last if end_condition(); # for some end condition redo; }