in reply to using split
You can use the separator retention mode of split by having memory parens in the split pattern:
my @names = split /\s+(AND|OR)\s+/, $blah;
In @names, you'll get the separator as every other element, and it's up to you to figure out how to deal with that according to your task.
Note that I adjusted your regex a bit. Since the whitespace are common to both, I put them outside of the alteration (those parens came in handy for grouping!), and I added the + one-or-more quantifier in case there are extra spaces next to each other.
Good luck :)
|
|---|