use strict;
my $str = 'Adapter - BNC Male to BNC-Female, Right Angle
Adapter - DB9 Female to DB9-Male, Null Modem Serial Adapter
Adapter - RCA Female to RCA-F
Adapter - DC Power 2.1x5.5mm Jack to 1.7x4.7mm Plug
Adapter - RJ45 Female (8-Pos) to DB25-M
Adapter - S-Video to Composite Video Adapter
Adapter - N Jack to UHF-M
Adapter - BNC Male to BNC-F, Right Angle
Adapter - DB9 Female to DB25-M, Serial Comms.
Adapter - DB9 Female to DB9-F, Null Modem Serial Adapter
Adapter - RCA Female to RCA-F, 10/pkg
Adapter - DC Power 2.1x5.5mm Jack to Dual 2.1x5.5mm Plug
Adapter - SMA Female to BNC-M
Adapter - DB25 Female to DB25-F, Slimline Gender Changer
Adapter - DC Power 2.1x5.5mm Plug to 9V Battery Clip, Ctr (+)
Adapter - USBA Female to USBA-F, Gender Changer
Adapter - USBA Male to USBA-M, Gender Changer
Adapter - DB9 Female to DB9-F, Slimline Gender Changer
Adapter - BNC Female to N-Type-M
Adapter - MCX Male to BNC-F
Adapter - DB15 Male to DB15-M, HD Slimline Gender Changer
Adapter - DB9 Male to DB9-M, Slimline Gender Changer
Adapter - SMA Male to BNC-F';
my $regex = qr/\b-\b/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