while (length($fifodata) > $MSG_SIZE) { my $msg = substr($fifodata, 0, $MSG_SIZE, ''); process_msg($msg); }