shmem,
Well, the title does say prefix($x, $y) . prefix($x, $z) eq $x. In this case, $x should be 'hello'. After your explanation and examining the code that I see you are listing all words that have the same prefix which is effectively the right thing - just not displayed as expected.