use warnings; use strict; use Getopt::Long; sub help { print "Available options are: \n"; print "\t--first\n"; print "\t--help\n"; } BEGIN{ # no warnings; #strangely this is not able to suppress the warning "Undefined subroutine &main::first called at.." GetOptions( 'first' => \&first, 'help' => \&help, ) or &help and die "Invalid options passed to $0\n" } sub first { print "Processing sub first\n"; } __END__ perl getoptcheck.pl --year --first Unknown option: year Undefined subroutine &main::first called at ..perl5.26.64bit/perl/lib/Getopt/Long.pm line 606. Available options are: --first --second --help Invalid options passed to getoptcheck.pl BEGIN failed--compilation aborted at getoptcheck.pl line 20.