I think you mean that you want to loop "non-blocking", meaning that you want to continue processing even if there is no user input. To do that, one usually uses 4-arg select, or the OO-wrapper interface IO::Select. Here's a trivial example to get you started.
use IO::Select;
# loop every 1 second
my $timeout = 1;
my $s = IO::Select->new();
$s->add(\*STDIN);
while ( 1 )
{
if ( my @ready = $s->can_read($timeout) )
{
# we got input
for my $fh ( @ready )
{
my $input = <$fh>;
print "got: $input";
}
}
else
{
# no input
}
# just to show that we're looping
print scalar localtime;
}
Update: I just remembered what select says about mixing buffered reading and "select", so even though the above code works, you might want to substitute the read via <$fh> with:
my $input;
sysread( $fh, $input, 1024);