in reply to Regex : Return match elements

split is your friend. Introducing a capture group in its regex adds the captured separators to the result, but it also adds undefs when the other alternative matches, so you need grep to filter them out.
my @array = grep defined, split / ([|&]) |\n/, $str;

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Regex : Return match elements
by ravi45722 (Pilgrim) on Jun 24, 2016 at 13:22 UTC
    first I also think for split but I am loosing '&' '|' while spliting. But you did the magic. thanks
      Split uses a regex (regular expression) to decide when to create elements of the resulting array. The code uses & or | to decide when to "make a new array element". Normally, in most splits, it is desired to "throw away" the split characters. Classic is: split /\s+/, $line; to parse space separated tokens. The use of a capture group in the regex allows the "splitted upon tokens" to appear in the output. This is an unusual situation, but works here.