in reply to Perl scoping not logical...?

Just replace
  sub do_pkg_need_from_Dist($$$$) {
with
  my $do_pkg_need_from_Dist = sub {
and then replace the calls to
  do_pkg_need_from_Dist()
with
  $do_pkg_need_from_Dist->()
and then everything will work out as you expect.