my $lownibble = (((unpack ("H", $byte[0]) << 4) >> 4)); The variable $lownibble prints the wrong value (value of $highnibble).