The 'perfect tense' is used to describe events in the past that had a definite ending whereas the imperfect tense if used to describe events which were ongoing. i.e. if we wanted to say: 'While Juan was eating the cake, he saw the dog', we know that 'was eating' is ongoing' and 'he saw' was sudden with a definite end. therefore when writing this in Spanish, we must conjugate appropriately. 'was eating' needs to be in the imperfect, either as 'comía' or 'estaba comiendo' and 'he saw' must go into the perfect as 'vio'. the sentence can then translate as 'Mientras Juan comía el pastel, vio al perro'.