The paper proposes a method to analyze the post-buckling response of a planar elastica subjected to unilateral constraints. The method rests on assuming a deformed shape of the elastica that is consistent with an assumed buckling mode and given unilateral constraints, and on uniquely segmenting the elastica so that each segment is a particular realization of the same canonical problem. An asymptotic solution of the canonical problem, which is characterized by clamped–pinned boundary conditions, is derived using a perturbation technique. The complete solution of the constrained elastica is constructed by assembling the solution for each segment. It entails solving a nonlinear system of algebraic equations that embodies the continuity conditions between the segments and the contact constraints. The method is then applied to analyze the post-buckling response of a planar weightless elastica compressed inside two rigid frictionless horizontal walls. The length of the elastica could be either constant, or variable, but the focus of the analysis is on the response of a variable length elastica, which is gradually inserted inside the conduit. In the insertion problem, a configurational force is generated at the insertion point, which is not present in the classical problem of a constant length elastica (Bigoni et al., 2015). The proposed approach is shown to lead to a simple and accurate numerical technique to simulate the constrained buckling of an elastica. The optimal sequence of equilibrium configurations of the elastica associated with a monotonic force- or displacement-control loading is deduced in accordance with the principle of minimum energy.