The problem seems to me to be distinguishing references rather than testing for whether or not it's a reference. Furthermore, the ref() of a list of objects might be its scope e.g. 'main', depending how it is passed. I would make a test version of the subroutine that prints out ref $_[0] and run it for each kind of test case before writing the rest of the code to handle the cases.