#!/usr/bin/env perl use 5.010; use strict; use warnings; say "Perl Version: $^V"; my $test_string = 'www xxx-A-B-C-D yyy zzz-E-F-G-H'; my $re = qr< \S+ (?: [A-Z]- ){2,} [A-Z] \b >x; say '=' x 60, "\n*** NO look-ahead ***\n", '=' x 60; my $no_look_ahead_test_string = $test_string; while ($no_look_ahead_test_string =~ /($re)/gp) { say "Prematch: '${^PREMATCH}'"; say "Match: '${^MATCH}'"; say "Postmatch: '${^POSTMATCH}'"; say '-' x 60; } say '=' x 60, "\n*** USING look-ahead ***\n", '=' x 60; my $look_ahead_test_string = $test_string; while ($look_ahead_test_string =~ /(?=$re)/gp) { say "Prematch: '${^PREMATCH}'"; say "Match: '${^MATCH}'"; say "Postmatch: '${^POSTMATCH}'"; say '-' x 60; }