in reply to removing duplicate letters

Here's a different approach. I may benchmark this later:
$newword = join '', split(/(\w+)\1/, $word);
Whoops, missed the + the first time! Let's say the first was a warm up, and the second actually works:
$newword = join '', split(/((\w)+)\1(\2{0,1})/, $word);
There. Appropriately hard to read.

Update: Yes, I had the backreferences backward, which breaks things, as the Anonymous Monk points out below. That'll teach me to be crafty.

Replies are listed 'Best First'.
RE: Re: removing duplicate letters
by Anonymous Monk on Jun 19, 2000 at 02:30 UTC

    Trying the latest suggestion...

    $s = "foooobaaaarrr";
    print "Before: $s\n";
    $newword = join '', split(/((\w)+)\2(\1{0,1})/, $s);
    print "After:  $newword\n";
    

    Result: no change. Not hereabouts, anyway.