in reply to XOR'ing to calculate a hex checksum

use List::Util qw( sum ); my $input = '000181080002020202020202'; my $sum = sum map { hex } split /([a-f0-9]{2})/, $input; my $xored_sum = 0xff ^ $sum; printf "hex of %d: %X\n", $xored_sum, $xored_sum; __END__ hex of 103: 67

I think what's going on in your code is that $lsb is a string, and it gets treated that way when you try to XOR it.

If you want the least significant byte of your sum (as it appears you do), you could just say $sum %= 256 without having to do a hex conversion.