in reply to Passing arguments

$#ARGV is the last used index in @ARGV. If @ARGV contains 1 element, $#ARGV will be zero. It's -1 if @ARGV is empty. You should use if (@ARGV) instead.