sub hex2 { my $str = shift; $str =~ s/^(0x|x)//; if (length $str) { if ($str =~ /([^0-9a-f])/i) { die "hex2: Illegal hexadecimal digit found: '$1'"; } else { return hex $str; } } else { die "hex2: No chars found after stripping leading 0x or x"; } }