use strict;
my $str = '
service.mensfitness.co.uk
updates.mensfitness.co.uk
promo.mensfitness.co.uk
deals.mensfitness.co.uk
subs.mensfitness.co.uk
service.healthandfitnessoneline.co.uk
updates.healthandfitnessoneline.co.uk
promo.healthandfitnessoneline.co.uk
deals.healthandfitnessoneline.co.uk
subs.healthandfitnessoneline.co.uk
service.custompc.co.uk
updates.custompc.co.uk
promo.custompc.co.uk
deals.custompc.co.uk
subs.custompc.co.uk
service.digitalslrphoto.com
updates.digitalslrphoto.com
promo.digitalslrphoto.com
deals.digitalslrphoto.com
subs.digitalslrphoto.com
';
my $regex = qr/[a-zA-Z0-9\-\_]*\.[a-zA-Z0-9\-\_]*\.\w{1,3}(\.\w{1,3})?/mp;
my $subst = '\'\\g<0>\'';
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