There are many different ways to do it.
Efficiency in a worms game might be important on a computer where speed is measured in Hertz, but yours is measured in gigahertz, so even a badly performing routine will be fast.
Consider that if you have 2 GHz to run, that's 2 billion cycles, or far more than 33 million cycles per frame. Modern CPUs can process several instructions every cycle. You would have to be extremely inefficient to require thirty million cycles to move a five segment worm.
Do the spheres stay put, or do they move? One way of handling the pieces in a game where the items don't move is to have a circular buffer. That is, if your worms are always 5 squares long, instead of moving where each item is at only modify where the head is.
When the head is 0, the body pieces are 1, 2, 3, and the tail is 4. When the head is 1, the body pieces are 2, 3, 4, and the tail is 0. When the head is 2, the body pieces are 3, 4, 0, and the tail is 1.
That way you can be lazy and only update a single value that tells you where the head is. You'll compensate by needing to track how far down the array each position is for the body and tail.
If you are growing and not always the same length, then you can copy each position one element down the row. You'll probably want to start from the tail, make the tail's position the same as the one before it, then move up the chain.
If all the pieces need to move, you'll need to figure out how they move in your game. Are they always moving toward the piece in front of them? What distance do they move? Often that is called a "delta", which is an old math term commonly used to indicate a distance changed. You can compute your snake's delta, or compute what direction the head needs to move, and then using whatever rules make sense for how you choose to implement your game, advance each piece down the line.