The medial temporal lobe (MTL) has been associated with declarative learning of flexible relational rules and the basal ganglia with implicit learning of stimulus-response mappings. It remains an open question of whether MTL or basal ganglia are involved when learning flexible relational contingencies without awareness. We studied learning of an explicit stimulus-response association with fMRI. Embedded in this explicit task was a hidden structure that was learnt implicitly. Implicit learning of the sequential regularities of the "hidden rule" activated the ventral perirhinal cortex, within the MTL, whereas learning the fixed stimulus-response associations activated the basal ganglia, indicating that the function of the MTL and the basal ganglia depends on the learned material and not necessarily on the participants' awareness.