in reply to Variable-width negative lookbehind

If the first character is 'Y', you want to remove all X's from index 2 on, otherwise remove them from index 1 on. That's a job for tr///d, and substr:

substr( $string, substr($string,0,1) eq 'Y' ? 2 : 1) =~ tr/X//d;
TIMTOWTDI.

Update: Or more succinctly, with $_, substr( $_, /^Y/ ? 2 : 1) =~ tr/X//d;

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Variable-width negative lookbehind
by Roy Johnson (Monsignor) on May 05, 2004 at 20:17 UTC
    ..or for a quick match, substr, and tr///d:
    $string =~ /^Y?X?/; substr($string, $+[0]) =~ tr/X//d;

    The PerlMonk tr/// Advocate
Re: Re: Variable-width negative lookbehind
by japhy (Canon) on May 05, 2004 at 19:56 UTC
    Très élégant.
    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;