$p = ($count = @ones = (sprintf '%b', $i) =~ /1/g) % 2;
sprintf %b converts the integer $i into a string of zeros and ones. This is matched against a '1' repeatedly (courtesy of the g regex modifier). The result of that is a list of matches returned into list variable @ones.
The list variable @ones is then assigned to scalar $count, which yields a count of the list items.
Modulo 2 of the count is then taken in order to get the parity. If the number of bits is odd, then there will be a one remainder, and one is taken as true by Perl
The list variable @ones is then assigned to scalar $count, which yields a count of the list items.
Modulo 2 of the count is then taken in order to get the parity. If the number of bits is odd, then there will be a one remainder, and one is taken as true by Perl