in reply to using variables in late contexts?

Your code should work, except that you need to replace:
%cmd_table{$test}
by
$cmd_table{$test}
You are refering to the value of a hash entry, not the hash itself, that's why you need $.

Oh, and there is no need for the @testarray (at least not in this snippet): just loop over the keys of %cmd_table, as in:

foreach $test (keys %cmd_hash) { # do your thing }
Hope this helps.

CU
Robartes-