#!/usr/bin/perl -w my $in = "abcdee3fgh1234eee"; my $out = ""; $out = join("",sort(split("",$in))); $out =~ s/(.+)\1/$1/g; print "in : $in\n"; print "out: $out\n";