use strict;
my $str = 'Parse email, also distorted ones, and convert them back to the real ones.
Inspirated by dislick\'s work: https://regex101.com/r/wB7xJ7/1
frenci98@gmail.com
st11389@copernico.bo.it
gigilafontana .at. gmail [dot] com
d98.copernico@gmail.com
domenico-tosello at dotcom-sas dot com
my.e-M4il [at] w3-spAce.org
email@sub-sub.sub dot domain dot info
email@foo dot foo dot foo dot foo';
my $regex = qr/^(?P<Username>[-\w\.]+)(?:\s+\W*at\W*\s+|\s*[^\@\s]*?@[^\@\s]*?\s*)(?P<Domain>([\w\-]+)(?:(?:\.|\s+\W*?dot\W*?\s+)([\w\-]+))+?(?:(?:\.|\s+\W*?dot\W*?\s+)([\w\-]+))??$)/mp;
my $subst = '\\1@\\3.\\4';
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