in reply to How to Modify Only Non-Quoted Words?

s { ([^"']*)? # non quoted part ("[^"]*")? # doublequoted ('[^']*')? # singlequoted } { my($x, $y, $z) = map {defined() ? $_ : ''} $1, $2, $3; $x =~ s/(?<!\S)(?=\S)/A/g; $x . $y . $z }xge;

Replies are listed 'Best First'.
Re^2: How to Modify Only Non-Quoted Words?
by Your Mother (Archbishop) on Aug 31, 2004 at 04:06 UTC

    Don't know if it's relevant to the problem but both your and ikegami's solutions fail when contractions enter into the "word" list.

      If you want to escape quotes oustide of quoted strings, change

      ( # $2 [^\s"']+ # Something to prefix. )

      to

      ( # $2 (?:[^\s"'\\]|\\.)+ # Something to prefix. )