in reply to How to use getopt and $#argv together?

getopt modifies the @ARGV array. Before you call getopt, you can store the number of original args passed to the script, then use the new variable instead of $#ARGV:
use Getopt::Std; use Data::Dumper; my $arg_num = scalar @ARGV; #Getting the command-line options my %options = (); getopt( "fdrv", \%options ); if ( exists $options{f} ) { if ( $arg_num != 7 ) { print "USAGE withouf option f\n"; } } if ( not exists $options{f} ) { if ( $arg_num != 5 ) { print "USAGE without option f\n"; } }