in reply to Auto-detecting returned or passed variable type

The problem I have is that I'm not sure what Function B is going to return. It may return a scalar, it may return an array or it may return a hash. It may even be a reference to one of these

That's not exactly right. Perl subroutines can return list of scalars. That's it. If you try to return something that isn't, it gets converted. The conversion occurs inside the function, so there's no way for the outside to know what was passed to return inside the function. Unfortunately, what you request cannot be done in Perl.

However, that doesn't mean there's no solution to your problem. There might be an alternative way of achieving what you want. Maybe there's a way of causing Function B that hasn't occured to you. Parse::RecDescent is very powerful and very flexible, so I'm sure we could find a way to help you if you were to post some of your code.