in reply to Regex triggering uninitialised values

The following works for me:

$str =~ s/(\d?)%var%(.*)/$1REPLACED$2/;

Replies are listed 'Best First'.
Re^2: Regex triggering uninitialised values
by kiat (Vicar) on Nov 19, 2004 at 17:46 UTC
    Thanks, jimbojones!

    What if I need to match more than one digit before %var%?

      Then you'd have
      $str =~ s/(\d*)%var%(.*)/$1REPLACED$2/;
      Although, unless you're going to use $1 and/or $2 later, there's no reason to have them at all.
      $str =~ s/%var%/REPLACED/;
      (\d*)