Distinguish multiple regex hits in a line?

Viewed 159

I'm trying to replace IP-Addresses with random numbers in Perl:

while (my $line = <file>){
    $line =~ $regex{'ipadress'};

    my $rand0 = int(rand(256));
    my $rand1 = int(rand(256));
    my $rand2 = int(rand(256));
    my $rand3 = int(rand(256));

    $& = "$rand0.$rand1.$rand2.$rand3\n";`
}

The problem is that in some cases there are multiple IP-Addresses in one line.
How to avoid that they all get the same random numbers?

3 Answers
Related