my $bin = pack("H*", ( length($hex) % 2 ? '0' : '' ).$hex); ... ( my $hex = unpack('H*', $bin) ) =~ s/^0+(?!\z)//;