in reply to How to remove duplicate characters in a string in place
A solution with s/// seems inefficient. And the loop is probably unavoidable: you'd need either variable lookbehind, or multiple matches on same text. Anyway:
my $str = "abcdefghiaabccdjklm"; print "Input : $str\n"; 1 while $str =~ s/(.)(.*?(?=\g1))((?=.+?\g1)|.)/$2/; print "Output: $str\n";
|
|---|