Thank you very much for your effort! I really did not expect some one to reply in such a short time and the solution actually worked! I just hit the F5 button and somebody just replied to my question and it was you! Before I could reply you came up with another update!
I will definitely learn from the example you gave me and understand it thoroughly and applied on other script as well.I've modified the script and applied on other scripts!! Thank you! But the script you gave me was hang after the first input. Giving me the error message of "system: 0/Bad file descriptor". But when i commented out the line " or die("system: $?/$!\n"); it works just fine!