use warnings; use strict; use Getopt::Long; my @actions; sub first { push @actions, 'first' } sub second { push @actions, 'second' } GetOptions(first=>\&first, second=>\&second) or die "Invalid options passed to $0\n"; for my $act (@actions) { if ($act eq 'first') { print "First!\n" } elsif ($act eq 'second') { print "Second!\n" } else { die $act } # shouldn't happen } __END__ $ perl 11140961b.pl --first --second --first --second --second --first First! Second! First! Second! Second! First! $ perl 11140961b.pl --first --second --year --first --second --second --first Unknown option: year Invalid options passed to 11140961b.pl