my $myObjs = { alpha => re('^alpha(.*)'), beta => re('\d+'), #myOptionalField => re('^opt(.*)'), #sometimes there is a "myOptionalField", but sometimes there is not. What to do? }; cmp_deeply( $response, { field1 => re('\d+'), field2 => 2, field3 => 1, objects => array_each($myObjs) }, 'testing for valid response structure' );