use warnings; use strict; use Getopt::Long; my @actions; GetOptions( first => sub { push @actions, \&first }, second => sub { push @actions, \&second }, ) or die "Invalid options passed to $0\n"; sub first { print "Processing sub first\n"; } sub second { print "Processing sub second\n"; } $_->() for @actions; __END__ $ perl 11140961c.pl --first --second --first --second --second --first Processing sub first Processing sub second Processing sub first Processing sub second Processing sub second Processing sub first $ perl 11140961c.pl --first --second --year --first --second --second --first Unknown option: year Invalid options passed to 11140961c.pl