my $text = <## ( ["The Moor's Last Sigh", "Salman", "Rushdie"], ["The God of Small Things", "Arundhati", "Roy"], ) #### if ($text =~ /$re1/mgc) { ... if ($text =~ /$re2/mgc) { ... if ($text =~ /$re1/mgc) { ... if ($text =~ /$re2/mgc) { ... #### # return ($1, $2, ...) matched against $s sub _groups { my $s = shift; my @groups; foreach my $i (1..$#-) { push @groups, substr($s, $-[$i], $+[$i] - $-[$i]); } return @groups } #### push @answers, [ _groups($text) ]; # [ ($1, $2, ...) ]