I forgot to mention, the easiest way to cut foam is with an electric carving knife. I put a 1x4" board on either side of the foam as a guide to make straight cuts. Have the part you want remove extend out from the board like a miter box for cutting wood.
I haven't tried DogFish's method, but for thinner pieces I've had good results with a thin, very sharp knife.
For thicker pieces, I've compressed the foam between two boards (if they are two narrow, the edge will be funny), and then using a thin, sharp blade.
I've also heard of (but not tried myself) of people soaking the foam in water and freezing it, and then drilling into it (to make a foam prefilter or something similar).