line = 'frame1 and frame2 or frame3' local keywords = { ["and"] = "and", ["or"] = "or",} print(line:gsub("[_%w]+", function(word) return keywords[word] or string.format("_G[%q]", word)end))