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! }