-- a, b is our "buffer" for last 2 chars pairs = {} function p(m, s) if s ~= nil then -- fill buffer for i = 1, s:len() do a = b b = s:sub(i) if a ~= nil then pairs[a] = b end end end return pairs[b] end