The s modifier might help you.
The  //s regex modifier would not seem helpful since it modifies the behavior of the  . (dot) regex metacharacter, and this metacharacter is used in neither the OP nor in your reply.

The OPer seems to be looking for a simple way to get the contents of the file as a single string. A simple way to do this is with the idiomatic statement
    my $string = do { local $/;  <$fh> }
(where  $fh is an already-opened file handle). After modification, this string can be printed with a single  print statement. Caution: this approach does not scale well to files of more than several megabytes (depending on your system's memory).

Also, the following regex accepts only balanced double-quotes on the "string" and requires the trailing '{' character.

>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 {
Updates:
  1. The  //g modifier which you use in your reply is, however, critical in a single-string solution!
  2. Added regex solution.

In reply to Re^2: Help with multiple line regex subsitution by AnomalousMonk
in thread Help with multiple line regex subsitution by gator456

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.