#!/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;
}
####
Perl Version: v5.12.3
============================================================
*** NO look-ahead ***
============================================================
Prematch: 'www '
Match: 'xxx-A-B-C-D'
Postmatch: ' yyy zzz-E-F-G-H'
------------------------------------------------------------
Prematch: 'www xxx-A-B-C-D yyy '
Match: 'zzz-E-F-G-H'
Postmatch: ''
------------------------------------------------------------
============================================================
*** USING look-ahead ***
============================================================
Prematch: 'www '
Match: ''
Postmatch: 'xxx-A-B-C-D yyy zzz-E-F-G-H'
------------------------------------------------------------
Prematch: 'www xxx-A-B-C-D yyy '
Match: ''
Postmatch: 'zzz-E-F-G-H'
------------------------------------------------------------
##
##
Perl Version: v5.14.2
============================================================
*** NO look-ahead ***
============================================================
Prematch: 'www '
Match: 'xxx-A-B-C-D'
Postmatch: ' yyy zzz-E-F-G-H'
------------------------------------------------------------
Prematch: 'www xxx-A-B-C-D yyy '
Match: 'zzz-E-F-G-H'
Postmatch: ''
------------------------------------------------------------
============================================================
*** USING look-ahead ***
============================================================
Prematch: 'www '
Match: ''
Postmatch: 'xxx-A-B-C-D yyy zzz-E-F-G-H'
------------------------------------------------------------
Prematch: 'www x'
Match: ''
Postmatch: 'xx-A-B-C-D yyy zzz-E-F-G-H'
------------------------------------------------------------
Prematch: 'www xx'
Match: ''
Postmatch: 'x-A-B-C-D yyy zzz-E-F-G-H'
------------------------------------------------------------
Prematch: 'www xxx'
Match: ''
Postmatch: '-A-B-C-D yyy zzz-E-F-G-H'
------------------------------------------------------------
Prematch: 'www xxx-'
Match: ''
Postmatch: 'A-B-C-D yyy zzz-E-F-G-H'
------------------------------------------------------------
Prematch: 'www xxx-A'
Match: ''
Postmatch: '-B-C-D yyy zzz-E-F-G-H'
------------------------------------------------------------
Prematch: 'www xxx-A-B-C-D yyy '
Match: ''
Postmatch: 'zzz-E-F-G-H'
------------------------------------------------------------
Prematch: 'www xxx-A-B-C-D yyy z'
Match: ''
Postmatch: 'zz-E-F-G-H'
------------------------------------------------------------
Prematch: 'www xxx-A-B-C-D yyy zz'
Match: ''
Postmatch: 'z-E-F-G-H'
------------------------------------------------------------
Prematch: 'www xxx-A-B-C-D yyy zzz'
Match: ''
Postmatch: '-E-F-G-H'
------------------------------------------------------------
Prematch: 'www xxx-A-B-C-D yyy zzz-'
Match: ''
Postmatch: 'E-F-G-H'
------------------------------------------------------------
Prematch: 'www xxx-A-B-C-D yyy zzz-E'
Match: ''
Postmatch: '-F-G-H'
------------------------------------------------------------