http://www.perlmonks.org?node_id=1027787


in reply to Get ranges from a list of numbers (like 1,2,3 => 1-3)

Quoth the CPAN:

print $set->as_string(), "\n"; # prints 1,3,5,7,9,100-1000000

It sounds like Set:IntSpan already does what you want. Just keep reading down the page a little further to Getting Set Contents