Iterative Learning Control (ILC) can significantly enhance the performance of systems that perform repeating tasks. However, small variations in the performed task may lead to a large performance deterioration. The aim of this paper is to develop a novel ILC approach, by exploiting rational basis functions, that enables performance enhancement through iterative learning while providing flexibility with respect to task variations. The proposed approach involves an iterative optimization procedure after each task, that exploits recent developments in instrumental variable-based system identification. Enhanced performance compared to pre-existing results is proven theoretically and illustrated through simulation examples