sub writeSerialPort { my $WRITE_TO_PORT = shift; $port->write($WRITE_TO_PORT) || die("Writing to the serial port failed: $!\n"); # STDOUT -> flush; sleep 2 } sub readSerialPort { sleep 3; $byte=$port->input; $buffer .= $byte; #print "\nBuffer: " . $buffer; #print "\n"; #print "\nByte: " . $byte; $byte = ""; # This variable is emptied each time new data comes in and is added to the buffer }