use strict;
my $str = 'Z2S22-1-5X=
Z2S22A1-5X/V
Z2S22-1-5X/
Z2S22-2-5X/
Z2S22A1-5X/
Z2S22B1-5X/
Z2S22-4-5X/
Z2S22-1-5X/V
Z2S22B2-5X/
Z2S22-3-5X/
Z2S22A2-5X/
Z2S22-3-5X/V
Z2S22A3-5X/
Z2S22B4-5X/
Z2S22A2-5X/SO40
Z2S22A4-5X/
Z2S22-2-5X/V
Z2S22B3-5X/
Z2S22B1-5X/V
Z2S22B1-5X/SO40
Z2S22A1-5X/SO60
Z2S22B1-5X/SO60
Z2S22A1-5X/SO40
Z2S22A2-5X/V
Z2S22B2-5X/V
Z2S22A4-5X/SO40
Z2S22A3-5X/V
Z2S22B1-5X/VSO60
Z2S22B1-5X/VSO40
Z2S22-4-5X/V
Z2S22B3-5X/SO40
Z2S22A1-5X=SO60
Z2S22B3-5X/V
';
my $regex = qr/^(?P<mounting_type>Z)(?P<number_of_function>2)(?P<unit_type>S)(?P<unit_size>22)(?P<function_in_port>A|B|-)(?P<cracking_pressure>1|2|3|4)(?P<sep_1>-)(?P<unit_series>5X)(?P<sep_2>/|=)(?P<surface_coating>|)(?P<seal_material>V|)(?P<special_version>SO40|SO60|)(?P<additional_details>(.|[0-9])*)$/mp;
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