use strict;
my $str = 'h1-c01.eset.com
h1-c02.eset.com
h1-c03.eset.com
h1-c04.eset.com
h1-c05.eset.com
h1-c06.eset.com
h1-c07.eset.com
h3-c01.eset.com
h3-c02.eset.com
h3-c03.eset.com
h3-c04.eset.com
h5-c01.eset.com
h5-c02.eset.com
h5-c03.eset.com
h5-c04.eset.com
h5-c05.eset.com
avcloud.e5.sk
dnsj.e5.sk
u.eset.com
c.eset.com
a.c.eset.com
i1.c.eset.com
i3.c.eset.com
i4.c.eset.com
i5.c.eset.com';
my $regex = qr/^(?:u|(?:a\.|i[1,3-5]\.)?c|h1\-c0[1-7]|h3\-c0[1-4]|h5\-c0[1-5])\.eset\.com|(?:avcloud|dnsj)\.e5\.sk$/mip;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
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