Just briefly scanning your code, it looks like you're working with a new array in your subroutine instead of the array reference you passed into it. When you do this:
my @level = @$level_ref;
... you've essentially taken a copy of the array that
$level_ref was pointing to. Then whenever you assign via
$level[$index], you're working with the copy that's scoped to your subroutine - and not with the original
@level that's scoped for the entire script.
There are two ways you could approach this. One way is to continue down the path you're trying to get on, and using $level_ref in your subroutine. In a nutshell, you'd replace code that was working with the subroutine scoped @level with code that uses the passed-in array reference $level_ref:
$level[$index]{"$employee_no-$emp_company_id"} = 1;
# ... becomes ...
$level_ref->[$index]{"$employee_no-$emp_company_id"} = 1;
Another way to solve the issue is to just work directly with the script-scoped @level, and forget about passing the reference around. This isn't exactly clean (it's the "global variable" approach), but hey, if it gets the job done... all you'd have to do is remove the line that declares @level within the subroutine:
my @level = @$level_ref; # delete this!
Hope this helps.