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