We reformulate the single-molecule analysis in an electron microscope in terms of a quantum-state discrimination problem, and discuss its implementation through electron-beam shaping. Our approach relies on the use of new electron-optical elements to efficiently extract the "which-molecule" information from the state of each electron. The optimal observables are formally derived, and subsequently implemented by suitably designed phase elements in a generalized orbital angular momentum sorter. As a representative example, we simulate the discrimination between model proteins and benchmark the performance of the sorter against that of the best known real-space approach.