in reply to Regex Tuning /(?:(?:foo[34])|(?:bar[12]))\.txt/io

Anchor the end. And you don't need the inner sets of parens.
/(?:foo[34]|bar[12])\.txt$/io

Caution: Contents may have been coded under pressure.