in reply to Crazy Golf : creating hex ranges from non-consecutive hex data values

Rather than fighting with hex, it almost always easier to work with integers internally and let Perl worry about formatting on input/output.
#!/usr/bin/perl use warnings; use strict; my @values = map hex, grep length, map split, <DATA>; my @ranges = [$values[0], $values[0]-1]; $_ == $ranges[-1][1]+1 ? $ranges[-1][1]++ : push @ranges, [$_,$_] for +@values; print "my \@hex = (\n"; printf "\t0x%05x .. 0x%05x,\n", @$_ for @ranges; print "\t);\n"; __END__ 00A0 00A1 00A2 00A3 00A4 00A5 00A6 00A7 00A8 00A9 00AA 00AB 00AC 00AD 00AE 00AF 00B0 00B1 00B2 00B3 00B4 00B5 00B6 00B7 00B8 00B9 00BA 00BB +00BC 00BD 00BE 00BF 00D7 00E6 00E7 00F0 00F7 00F8 0127 0131 014B 0153 0192 +019B

where I've truncated the DATA section for brevity. The above outputs

my @hex = ( 0x000a0 .. 0x000bf, 0x000d7 .. 0x000d7, 0x000e6 .. 0x000e7, 0x000f0 .. 0x000f0, 0x000f7 .. 0x000f8, 0x00127 .. 0x00127, 0x00131 .. 0x00131, 0x0014b .. 0x0014b, 0x00153 .. 0x00153, 0x00192 .. 0x00192, 0x0019b .. 0x0019b, );

If the assumption of being well-ordered fails, inserting a sort {$a<=>$b}, before the maps will fix you. Repeat values are a bit more annoying - they won't result in invalid output, but they will create unnecessary breaks and overlapping ranges.

The range-generation algorithm is fairly simplistic - keep an AoA of start and end points, and if the next point is one larger increment the last range; otherwise, create a new one.