I can't quite tell if you're processing command line arguments or not. So if not, ignore the rest of this post.
Processing command-line arguments can get tricky, so I won't talk you out of doing it yourself. However, I *do* want to point out that it's complex enough that various people have created various packages to handle them. You may find it worth your while to use one of them, rather than wrestling with subtle errors as you add yet more options. I usually use Getopt::Long, but you should review several before choosing. Getopt::Long is pretty flexible, but requires a bit more effort than some others, so you might not like it as much as I do.
When your only tool is a hammer, all problems look like your thumb.