Let Φ = {φ i : i ∈ Λ} be an iterated function system on a compact metric space (X, d), where the index set Λ = {1, 2, . . . , l} with l ≥ 2, or Λ = {1, 2, . . .}. We denote by J the attractor of Φ, and by D the subset of points possessing multiple codings. For any x ∈ J\D, there is a unique integer sequence {ωn(In this case we write x = [ω 1 (x), ω 2 (x), . . .]. For x, y ∈ J\D, we define the shortest distance function Mn(x, y) as Mn(x, y) = max k ∈ N : ω i+1 (x) = ω i+1 (y), . . . ,ω i+k (x) = ω i+k (y) for some 0 ≤ i ≤ n − k , which counts the run length of the longest same block among the first n digits of (x, y).In this paper, we are concerned with the asymptotic behaviour of Mn(x, y) as n tends to ∞. We calculate the Hausdorff dimensions of the exceptional sets arising from the shortest distance function. As applications, we study the exceptional sets in several concrete systems such as continued fractions system, Lüroth system, N -ary system, and triadic Cantor system.