Line1 = io.read() Line2 = io.read() I,J = Line2:match("(.) (.)") -- boobs return the char flags i = Line1:find(I) -- find location of flags j = Line1:find(J) K,c = Line1:gsub(I,'') -- replace flag w/ empty & store in K _,b = K:gsub(J,'') -- taking K ensures single flags fail if i > j then i,j=j,i end -- ensure we start low to high if i==j or not (c+b==2) then print('"null"') else print('"'..Line1:sub(i+1,j-1)..'"') end