my $buffer; while (1) { read( PORT, $byte, 1 ); $buffer .= $byte; if ( length( $buffer )) { printf( "Buffer now has %d bytes; last byte read was 0x%02x\n", length( $buffer ), $byte ); } }