Thanks everyone for the help. I used the feedback to now use a substitution in the string variable that may contain one or more IP addresses:
my $Event_text="This is a test string with a possible IP address: 10.10.10.100 but there is also 20.20.20.256";
my $New_text = $Event_text;
if ( $New_text =~ /\b$RE{net}{IPv4}\b/ )
{
print "IP FOUND\n";
$New_text =~ s/$RE{net}{IPv4}/ "X.X.X.X" /eg;
$Event_text = $New_text;
}
else
{
print "No IP\n";
}
print "Event_text: $Event_text\n";
This mostly works. But with this code, when one of the IPs in the string is invalid, it returns this output:
Event_text: This is a test string with a possible IP address: X.X.X.X but there is also X.X.X.X6
So you can see that it's trying to substitute the invalid octet "256" but it does so by leaving the last digit (6) for some reason.
I think the substitution requires a tweak around the $RE{net}{ipv4}. The description of the Regexp::Common does say "To prevent the unwanted matching, one needs to anchor the regexp: /^$RE{net}{IPv4}$/". But it's not clear how to implement that.