in reply to filehandles and such

You have several problems here. One big one is that I really can't tell what you're trying to do, for one thing. :)

But as for Perl problems, you've got some things incorrect:

  1. You have "for each (@sample) {". "foreach" is one word, not two.

  2. You have the following code:
    sub encode { my(@sample=@_); $site=&findsite($sample);
    There are some real problems here, the biggest being that @sample is not the same as $sample. So you're passing an undefined argument into each of your subroutines. The other problem is w/ those subroutines...
  3. You're using the return values of the subroutines, but you're not actually returning anything!
Your code doesn't even compile, so you can't actually be running this. Could you describe more clearly what it is that you're trying to do? Maybe then we could help you out more.