in reply to Re^2: Search replace with a block
in thread Search replace with a block

There are many, many different ways to approach this and identifying which is simplest is a very subjective measure. Try some of the approaches and see which you think appears simplest to you and just go with that one. TIMTOWTDI.

You could construct a single regex to do a multiline match and replace but that will certainly be far from the simplest approach. I would recommend Apache::Admin::Config over such a complicated approach any day. Note that this is a pure-perl module so you can just use the source if necessary.

However, here's the general all-in-one method:

#!/usr/bin/env perl use strict; use warnings; my $in = <<EOT; <Location /> MaxConnPerIP 12 NoIPLimit image/* </Location> EOT my $max = 16; my $out = $in; $out =~ s/(<Location .+?MaxConnPerIP\s+)(?:\d+)(.+?<\/Location>)/$1$ma +x$2/s; print $out;