in reply to How can I reduce this with a REGEX?

Or using a data pipeline with sort and grep:
use strict; use warnings; my @strings = qw( 12-12 12-12-12 12-13-12-13 12-12-13-13 12-13-13-14 ) +; for (@strings) { my $prev = -1; # numbers being separated by dashes, I assume that +a negative value is not possible print join "-", grep {$prev != $_ and $prev = $_} sort {$a <=> $b} + split /-/, $_; print "\n"; }
which prints:
12 12 12-13 12-13 12-13-14