x = 'PLAN_someFile_to_work_ZZTT'
y = 'FOR_someOtherFile_XXYY'

def split(x):
    z = x.split('_')
z[1] = '_'.join(z[1:-1])
del z[2:-1]
return z
print(split(x))
print(split(y))
Manipulation of variable length prefix string