Since Xfoil is using potential flow theory, how is it able to predict boundary layer and separation? If I'm adding perturbation terms aren't those still made with fundamental flows?
The answer is in the resolution of the boundary layer by solving integral equation, for which a potential solution is needed (see this answer). XFoil uses Thwaites method coupled with Michel method. In particular it uses the local Reynolds number to understand if transition happened or if separation happened on the airfoil surface.
XFOIL uses a potential code for inviscid calculation (the prompt then reads OPERi) and outside of the boundary layer in viscous mode (OPERv).
The boundary layer calculation needs the speed and pressure information from the potential part but then uses an integration method for the boundary layer and iterates the solution, until a set of residual errors is driven below a pre-determined threshold. This iteration is needed to find the correct boundary layer thickness that agrees with the parameters of the potential flow solution around the airfoil plus this boundary layer.
The boundary layer formulation used by XFOIL is described in: Drela, M. and Giles, M.B. Viscous-Inviscid Analysis of Transonic and Low Reynolds Number Airfoils AIAA Journal, 25(10), pp.1347-1355, October 1987.