use strict; use warnings; use Getopt::Long; my $prod_type = ""; my $in_file = ""; my $out_file = ""; my $img_file = ""; my $valid = GetOptions( 'p=s' => \$prod_type, 'i=s' => \$in_file, 'o=s' => \$out_file, 'h=s' => \$img_file, ); if (($in_file eq "") and ($img_file eq "")) { my $msg = ""; die "Missing required option(s). The -i or -h option must be specified."; } if ($in_file ne "") { # do some stuff and ignore the -h flag } else { # do other stuff # earlier if statement guarantees that -h flag was used # i.e there was no -i flag used, but the -h flag was used }