in reply to infinite loop on while (@array)
You might want to reconsider for and foreach, or better yet try to give a more thorough explanation of why you believe you cannot use them.
-- perl -pe "s/\b;([st])/'\1/mg"