Masquerading prey gain protection from their predators by being misclassified as an inedible or uninteresting part of the environment. It has recently been demonstrated that twig-mimicking caterpillars benefit from masquerade; and that size disparity between twigs and caterpillars reduces protection from relatively naive predators. Using an established experimental system in which domestic chicks Gallus gallus domesticus predate twig-mimicking caterpillars of the Early Thorn Moth Selenia dentaria, we show that this effect is even stronger when predators have the opportunity to learn that size is an effective cue for discrimination. However, using a series of binary choice tests, we also show that caterpillars are able to minimize predation risk by selecting microhabitats that enhance the benefits of masquerade: those containing size-matched twigs. Furthermore, caterpillars trade off the relative benefits of protection from predation and feeding, when branches that provide the best protection from predation do not contain food. Finally, both the preferred microhabitat and the strength of caterpillars’ preferences for that habitat change with size: small caterpillars prefer branches with small twigs over branches with large twigs, and the reverse is true of large caterpillars; and preferences tend to be stronger in larger caterpillars, perhaps because of their increased detectability and desirability to predators.