use strict; use warnings; use Regexp::Common 'net'; my $input = <<'EOI'; EOI my $want = <<'EOW'; EOW my $replacement_ip = '10.10.25.18'; $input =~ s/()/$1$replacement_ip$2/; print $input eq $want ? "Success:\n" : "Failure:\n"; print "\t$_\n" for split /\n/, $input; #### Success: #### (?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2}))