in reply to whats wrong with my sub-routine ??

Start by saying
use strict; use warnings;
and your typos (using a global variable where you meant to use a parameter) will be pointed out to you.

—John