Flat pillows with removable blocks can be made from builders insulation boards available from a local hardware store. But the best foam is a “closed cell polethylene foam” like Ethafoam. If you have an extruded polystyrene foam board (XPS), (the insulation boards from a hardware store), it would be suitable. It won’t last forever, but it will last a fair while.
Put a layer of old woollen blanket or felt on top of each block, and cover tightly with well washed 100% cotton fabric. I make my fabric covers in two parts, and hand stitch down the sides and around the bottom, pulling the edges together for a tight fit. And when a pin has to be placed where two blocks meet, I just angle the pin slightly. The picture is of board I recently made. The side blocks are glued, cover and all, onto an MDF base, but the three centre blocks are moveable. There is a piece of quad wood glued across the bottom so they don’t slip out. Centre blocks are 150x150mm, the sides 450mmx150mm with a slight slope trimmed off one long edge.