How to do them ? Please give me a hint
Do you want a hint with the algorithm or do you want a hint with the code? What have you already tried?
Generic Hint: Start with a smaller problem and work up. eg. suppose instead of changing the order of the contents you just wanted to do the prepending with "logic " - do that first as it should be pretty easy given the resources of perlintro, perlrun and print. Can you construct an algorithm to do this? Can you convert the algorithm into code?
We cannot help you if we don't know what's holding you back.