{ local $/ = chr(0); # if this occurs reasonably often in the file open (FILE, "file.binary"); while ( ) { while ( length() ) { my $byte; ( $byte, $_ ) = /^(.)(.*)$/; ... Code here, processing $byte ... } } close FILE; }