I would like to expand on Rory's answer.
You can think about the DNA like a very complex book of recipes (genes) for constructing cellular machinery (e.g. proteins). Every genome has a large repertoire of machines that it can construct. For a given organism, all its somatic cells will have the same DNA (more or less, but let's put that aside) since it starts out as a single cell. In spite of this, you can see that cells can have completely different shapes and functions. For example, look at how different a neuron is from a muscle cell or a blood cell in terms of shape and function. In addition, cells can change in reaction to their environment.
Then how is the repertoire the same but the cells completely different?
The solution is choosing which genes to activate. This is the called gene regulation and is an extremely complex system as you might guess. It is to some extent the "brain" of the cell, with which the cells can make decisions and gain its plasticity in biological function. This system operates on many levels, one of them being by controlling transcription, i.e. transcriptional regulation, which controls how much RNA to make from each gene, which will later translate into some level of activation (no RNA means the gene will not be active). This is why the RNA will probably vary widely according to the cell type and cellular state.
In general, each species have a similar DNA sequence give or take some minor variations. The sequence of family members will be even more similar, and the sequence of clones (e.g. identical twins) will be virtually identical. This type of variation is random and thus will not be used as a control system. From this you can already guess that the change from caterpillar to butterfly will be controlled by its gene regulation program, as it is a developmental change, in the same way as a human grows from a single embryonic cell.
That said, it is always possible that some random changes occur somewhere along the way and would cause differences, as biology is stochastic. However, for these to be consistent between all cells in the organism, they would have to happen when the organism is a single cell, which is not the case when transitioning from caterpillar to butterfly.