but it don't seem to do the job , do you see the problem
And after all that code you were so close! The problem is that your code probably runs just fine, but doesn't do what you thought it ought to. You don't appear to be using strict, otherwise I'd guess the above snippet wouldn't even compile. Or, as another possibility, you set all your $VARIABLES somewhere else in the script, but don't show us where. And finally, you tell us what you're trying to do, but you don't tell us what post-conditions you are finding that are unsatisfactory, or what error messages your script is generating. Unless you give us this information, we're forced to guess at what you meant to ask, what other code this script might contain, and what you really mean when you say "it don't seem to do the job".