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";
In reply to Re: How to remove duplicate characters in a string in place
by Anonymous Monk
in thread How to remove duplicate characters in a string in place
by punitpawar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |