Poster jbeng was thinking along the same track as myself...but your question leaves out a lot of details that might be relevant.
What will actually be moving back and forth? I mean what sort of object will be actuating this switch? Will it be constant contact, intermittent contact, or a combination of both?
Will your switch be some way causing a response in your object, or is it simply going to a counter circuit, visual indicator, or triggering something else of another nature?
If you are simply looking for an intermittent, momentary contact closure per each pass of the object by the switch, a roller type switch would certainly work, or a rocker style would work if you want an on/off/on/off switch closure.
You could also purchase a snap action switch with multiple poles if you have more than one circuit to trigger...the method of actuating one of these switches can be fabricated by the user: **broken link removed**
And of course one of the easiest ways to do it, if a flag can be passed through, is the forked light barrier (optical) switch. Is there a particular reason this is out?
Or a hall effect sensor might be used if a magnet can be fixed to your object.
Or if you are still inclined to mechanical switching, a reed switch or simple magnetic switch can do as you want without even making contact with your object.