for my $index (0..5) { my $thisrow = $nextrow - $index; print "processing row/column/bit $thisrow/$col/$subcol: " . substr($binimage[$thisrow], $col, 1) . "\n"; printf ("Incoming byte is %d/%x/%8b/%s. Test bitmask is %d/%x/%8b/%s.\n", substr($binimage[$thisrow], $col, 1),substr($binimage[$thisrow], $col, 1),substr($binimage[$thisrow], $col, 1), unpack('B8',substr($binimage[$thisrow], $col, 1)), 2**(7-$subcol), 2**(7-$subcol), 2**(7-$subcol), unpack('B8', 2**(7-$subcol))); substr ($char, $index + 2, 1) = ((substr($binimage[$thisrow], $col, 1)) & 2**(7-$subcol))? "1" : "0"; # Update tracker where a "1" is found! } #### processing row/column/bit 5/0/0: (unprintable square box symbol) Incoming byte is 0/0/ 0/00000000. Test bitmask is 128/80/10000000/00110001. processing row/column/bit 4/0/0: (unprintable square box symbol) Incoming byte is 0/0/ 0/00000000. Test bitmask is 128/80/10000000/00110001. processing row/column/bit 3/0/0: (unprintable square box symbol) Incoming byte is 0/0/ 0/00000000. Test bitmask is 128/80/10000000/00110001. processing row/column/bit 2/0/0: (unprintable square box symbol) Incoming byte is 0/0/ 0/00000000. Test bitmask is 128/80/10000000/00110001. processing row/column/bit 1/0/0: (unprintable square box symbol) Incoming byte is 0/0/ 0/00000000. Test bitmask is 128/80/10000000/00110001. processing row/column/bit 0/0/0: ? Incoming byte is 0/0/ 0/10010000. Test bitmask is 128/80/10000000/00110001. ...