[ 11, 22, # optional [ [ 1 ], [ # -1 # only here if 2 above is there ] # ] ] #### use Test::More tests => 2; use Test::Deep; my $id_re = re('^\d+$'); my $vpt_re = re('^-?1$'); my $x = [ '11', '22', [ [ '-1', ], [ # '1', # only present if '22' above present ] # ] ]; my $y = [ '11', [ [ '-1', ], ] ]; my $comp = [ $id_re, $id_re, subbagof([$vpt_re], [$vpt_re]) ]; cmp_deeply($x, $comp, 'test1'); cmp_deeply($y, $comp, 'test2');