use strict; use warnings; sub elide { my ($start,$end) = @_; if ((my $diff1 = length($end) - length($start)) > 0) { return "$start-$end"; } elsif ($diff1 == 0) { if ($start == $end) { return $start; } else { if ((my $diff2 = length($end) - length($end - $start)) > 0) { $end %= 10 ** (length($end) - $diff2); } return "$start-$end"; } } } while ( ) { print elide( split ' ', $_ ), "\n"; } __DATA__ 1 32 4 19 28 39 34 123 321 321 324 329 325 349 340 509 999 1000 1000 1001