open( $com, "+<","/dev/ttyUSB0" ) || die "Cannot open serial port : $!\n"; while( 1 ) { my $in = <$com>; # input # do stuff here ( You should be able to do both input and output within the loop. print $com "..."; # output if ( $in eq "quit" ) { last; } }