http://www.perlmonks.org?node_id=11112672


in reply to Regex. Combination of words block. Need help.

Why do you need to do this all in one regular expression?

Also, do you mean that the space in front of  ccc should be treated differently from the space between abc Qwerty?

Also, why does Qwerty not show up as a separate string in your other examples?

If you want a simple approach, just split the string on /[;,\s]+/ to get an array, and then get all the sub-sequences of that array:

#!perl use strict; use warnings; my $string = 'aaa, bbb, ccc,ddddd;eee-12345abc Qwerty'; my @items = split /[,;\s]+/, $string; for my $i (0..$#items) { for my $j ($i..$#items) { print join " - ", @items[ $i .. $j ]; print "\n"; }; } __END__ aaa aaa - bbb aaa - bbb - ccc aaa - bbb - ccc - ddddd aaa - bbb - ccc - ddddd - eee-12345abc aaa - bbb - ccc - ddddd - eee-12345abc - Qwerty bbb bbb - ccc bbb - ccc - ddddd bbb - ccc - ddddd - eee-12345abc bbb - ccc - ddddd - eee-12345abc - Qwerty ccc ccc - ddddd ccc - ddddd - eee-12345abc ccc - ddddd - eee-12345abc - Qwerty ddddd ddddd - eee-12345abc ddddd - eee-12345abc - Qwerty eee-12345abc eee-12345abc - Qwerty Qwerty