in reply to using an RE to consolidate repeated words

You need to use a back reference.
$after =~ s#^(\w+)/\1#$1#;

Tidying up the syntax and changing the test for the bit in between the repeats gives:

$after =~ s/(\w+)\W+\1/$1/;
I assumed that there is no need to anchor the pattern to the start of the string so I removed the ^