If I replace <STDIN> with 'filename' , it uses the file appropriately
Not quite. You actually have to replace <STDIN> with a file handle, not a filename.
If you get the filename from the command line like you want to, it ends up in @ARGV. The first argument on the command line is in $ARGV[0], the second in $ARGV[1], and so on. Using a simple shift like akho has suggested simply grabs (and removes) the first element off of @ARGV. You could also do this: $basename = $ARGV[0]
If you gave us some more information, we could offer much more advice. I have a feeling that these answers will only lead to more questions, so bring it on.