Sorry: I don't understand sense of this in any way
As it is coded now you change the string that's been looped upon
for every pass. (I.e. for every pass delete the '2' - though after the first there will be none left.) Seems nonsense? Do it once *before* the loop?
And I would
never ever change the string I'm looping on. (I.e. $a.)
*If* the change would be conditional, and so would have to take place *inside* the loop, I would copy the original string to a new variable, with any appropriate change, but never touch the original.
By the way: in the original version, on start of loop, $a is copied, and the loop is working on this copy - so a change
*can* have no effect. I would say this is is absolutely correct.
And to say: the Unset doesn't make any sense, too. It's same as always locking a door before opening it. After opening it it's open - no matter what it was before.
My 2 ct