>perl -wMstrict -le "my $s = join '', @ARGV; $s = eval qq[qq[$s]]; my $words = qr{ foo | bar }xms; $s =~ s{ (Kw \s+) (\"?) ($words) (\2 \s* \{) }{$1${2}1_$3$4}xmsg; print 'output:'; print $s; " "Kw \n foo \n { \n Kw \n \"bar\"\n { \n Kw foo { Kw \"foo\" { " "Kw \"foo { Kw foo\" { Kw foo Kw {" output: Kw 1_foo { Kw "1_bar" { Kw 1_foo { Kw "1_foo" { Kw "foo { Kw foo" { Kw foo Kw {