title: Perl/Sed command to replace same pattern multiple times
body: <p>I need to set <code>disable=no</code> in <code>/etc/xinetd.d/chargen</code> using commands like perl or sed.</p>
  
  <p><code>/etc/xinetd.d/chargen</code> content is:</p>
  
  <pre><code># description: An xinetd internal service which generate characters.  The
  # xinetd internal service which continuously generates characters until the
  # connection is dropped.  The characters look something like this:
  # !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefg
  # This is the tcp version. 
  service chargen
  {
          disable         = yes
          type            = INTERNAL
          id              = chargen-stream
          socket_type     = stream
          protocol        = tcp
          user            = root
          wait            = no 
  }
  
  # This is the udp version. 
  service chargen
  {
          disable         = yes
          type            = INTERNAL
          id              = chargen-dgram
          socket_type     = dgram
          protocol        = udp
          user            = root
          wait            = yes 
  }
  </code></pre>
  
  <p>I have used perl command <pre>
  <code>perl -0777 -pe 's|(service chargen[^\^]+)disable\s+=\syes|\1disable=no|' /etc/xinetd.d/chargen</code> </pre>
  but it is replacing at only one place.</p>
  
  <pre><code># description: An xinetd internal service which generate characters.  The
  # xinetd internal service which continuously generates characters until the
  # connection is dropped.  The characters look something like this:
  # !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefg
  # This is the tcp version.
  service chargen
  {
          disable         = yes
          type            = INTERNAL
          id              = chargen-stream
          socket_type     = stream
          protocol        = tcp
          user            = root
          wait            = no
  }
  
  # This is the udp version.
  service chargen
  {
          disable=no
          type            = INTERNAL
          id              = chargen-dgram
          socket_type     = dgram
          protocol        = udp
          user            = root
          wait            = yes
  }
  </code></pre>
  
  <p>what is the proper command to make it work in both places? </p>
  
  <p><strong>NOTE</strong>: I could have replaced <code>disable         = yes</code> with <code>disable         = no</code> without matching <code>service chargen</code> but I need to use same sed/perl command to replace in <code>/etc/xinetd.conf</code> which will have other services too. </p>
  
  <p><strong>UPDATE</strong> As Jonathan highlighted in his comment, disable can be at any position inside the flower bracket.</p>