Pupil dilation has been associated with increased cognitive load or mental effort requirements, which can be modulated by external sensory stimulation as well as internal cognition. Underlying a cognitive task are multiple interplaying processes which can be stimulus-driven, goal-driven or spontaneous. However, what remains unknown is how these multiple processes correlate with pupil size modulations and whether it is possible to dissociate their individual effects. To answer this, we employed behavioural and pupil data from two cognitive tasks performed in internal and external attention conditions, where stimulus-driven attention demands were manipulated for the same set of tasks. Using model-based analysis, we were able to dissociate within conditions, how individual processes affect pupil and also compare their effects between conditions. We made two important and novel findings – first, within both the conditions we were able to dissociate stimulus-driven and goal-driven effects. Second, when compared between the two attention conditions, we found distinct stimulus-driven attention-based effects but similar goal-directed task-based effects. Our results indicate that pupil can be used as a reliable tool to study cognition.