my $wanted = 'CODE'; # if key3 has a value but not a CODE ref, it croaks my $code = thefunc($somedata, $wanted, 'key1', 'key2', 'key3'); $code->(@someargs);