use strict;
my $str = 'https://live-rv.duizhuang.com:123aaa/bb
https://live-rv.duizhuang.com:123/aaa/bb
https://live-rv.duizhuang.com/aaa/bb
https://live-rv.duizhuang.cn2/aaa/bb
https://img.dz8.cn/2/aaa/bb.png!/1/1
';
my $regex = qr/(?:(?<=\.(?:com|cn)(\:\d+(?!\d)))|(?<=\.(?:com|cn)(?!:\d+|\.)))(?!\/)/p;
my $subst = '/';
my $result = $str =~ s/$regex/$subst/rg;
print "The result of the substitution is' $result\n";
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html