in reply to Why my code working...why my code is not working...

How can I debug this behavior?
Um ... Use the built-in perl debugger -?

BTW "not working" is not a particularly descriptive problem statement.

             "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius