>When I run this I get all kinds of complaints on the $hits line. I've >tried various modifications, but can't seem to get it to work. Any >idea of what's wrong here?

Probably, trying to use Perl as a shell scripting language. In which case you'd better write a shell script in the first place. There's "almost" nothing awk can do that Perl can't. So please describe your task instead. Someone will come up with an example Perl version.