$after =~ s#^(\w+)/\1#$1#;
Tidying up the syntax and changing the test for the bit in between the repeats gives:
I assumed that there is no need to anchor the pattern to the start of the string so I removed the ^$after =~ s/(\w+)\W+\1/$1/;
In reply to Re: using an RE to consolidate repeated words
by inman
in thread using an RE to consolidate repeated words
by jaa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |