open (IN, "< ./someinputfile") || die $!; open (OUT, "> ./someoutputfile") || die $!; binmode IN; binmode OUT; my $read = 1; my $result; while($read > 0){ $read = read IN,$result,1; #do some processing and checking here. #convert the bits to bytes print OUT $result; }