At this point $binPet =~ s/^0+(?=\d)//;
$binPet contains the string '10' and then when you print out that string in printf "%s%bn%s", "\n", $binPet, "\n";, it gives the binary representation of ten, (1010), not a binary '2', (0b10).
And I don't know the purpose of 'n' in the printf format string, "%s%bn%s".
Beyond that, I'm not sure of what to tell you - the purpose of the code.
Comment on Re: having trouble unmasking a binary string