while(){ %h = (); undef $h{$1} while(s/(\d\d)//); print join ("-", sort keys %h),"\n"; } __DATA__ 12-12 12-12-12 12-13-12-13 12-12-13-13 12-13-13-14