in reply to (jeffa) Re: Illegal hexadecimal digit error
in thread Illegal hexadecimal digit error

Or even better, put it all in sprintf:
my $hex_num = sprintf("0x%x", $dec_num);