in reply to saving a split pattern

If you use parenthesis around your pattern, it will appear in the returned list:
use strict; use warnings; my $s = 'PRELUDExz3456MIDDLEzy1234POST'; my @list = split m/([a-z]{2}\d{4})/, $s; print "@list\n"; __END__ PRELUDE xz3456 MIDDLE zy1234 POST

Replies are listed 'Best First'.
Re^2: saving a split pattern
by tinita (Parson) on Nov 04, 2008 at 12:30 UTC
    just wanted to note the alternative, if the pattern should not be in an extra element:
    my @list = split m/(?=[a-z]{2}\d{4})/, $s;
    output:
    PRELUDE xz3456MIDDLE zy1234POST