use strict; use warnings; use Regexp::Common qw /net/; my $string ='194.66.82.11'; $string =~ s/$RE{net}{IPv4}{-keep} /'x'x(length $2) . '.' . 'x'x(length $3) . '.' . 'x'x(length $4) . '.' . $5 /xge; print $string;