in reply to Output numbers in hex

The variable $hex_num doesn't "know" that the number is in hex, just that it's an integer. Your code as written is actually equivalent to this:
$hex_num = 3914; print $hex_num;

What you might want is this:

$hex_num = 0xf4a; printf "0x%x", $hex_num;