use strict;
my $str = 'H-4WEH62HE5XF/10EG24N9S2K4
H-4WEH62HD5XF/OF10EG220N9SK4/B10V
H-4WEH62HH5XF/10EG24N9K4
';
my $regex = qr/^(?P<operating_pressure>H)(?P<sep_1>-)(?P<number_of_main_ports>4)(?P<unit_type>W)(?P<actuation_type>EH|H)(?P<unit_size>62)(?P<spool_feedback_main_stage>H|)(?P<spool_symbol>C|D|K|Z|E|F|G|H|J|L|M|Q|R|S|T|U|V|W)(?P<unit_series>5X)(?P<mounting_type>F|)(?P<sep_2>/)(?P<spool_feedback>OF|O)(?P<pilot_valve>10)(?P<type_of_solenoid>A|L)(?P<solenoid_in_ac_or_dc_version>G|W)(?P<voltage_of_solenoid>220|195|180|127|120|110|96|60|42|24|12)(?P<voltage_rectifier>R|-|)(?P<manual_override_unit>Y|)(?P<spool_position_monitoring>Y|)(?P<unit_for_time_adjustment>S2|S|)(?P<electrical_connection>Z5L|Z2L|Z1L|DKL|DZL|DL|DZ|DK|ZL|KL|Z5|Z4|Z2|Z1|D|L|Z|K|)(?P<sep_3>/)(?P<additional_equipment>17|16|15|14|13|12|11|10)(?P<orifice_positon>B|)(?P<orifice_diameter>15|12|11|10|08|)(?P<seal_material>V|)(?P<additional_details>)$
/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