our $pat; $pat = qr! (?: \[ (?> (?>[^\[\]]+) | (??{$pat}) )* \](?:\,\s)* ) !x; if( $s =~ /\[$x1\,\s?($pat)*\[\[?$x2/ ) { return 1; }else{ return 0; }