Yeah! I did that. I put in a few print statements to see what is being printed.
So when I execute "print $year", it gives me the desired result, but if the same I put it in the DateTime->new, it gives an error.
I read on the DateTime and found that it is expecting an int value. I tried converting the $year to an int, using the int function ... int($year) ... but that made $year to 0. Strange!
I read the manuals and did a lot of trials and errors, then since none worked, I thought of putting it up here