use strict; use warnings; use Getopt::Long; my @current_params; my $counter; while ( @current_params = get_next_set() ) { $counter++; print "\nloop $counter:"; local @ARGV = @current_params; my ($alpha,$beta,$gamma); GetOptions ( 'Alpha|a' => \$alpha, 'Beta|b' => \$beta, 'Gamma|g' => \$gamma, ); if ( $alpha ) { print "ALPHA FOUND." } if ( $beta ) { print "BETA FOUND." } if ( $gamma ) { print "GAMMA FOUND." } } ######################## sub get_next_set ######################## { my @temp_set; while ( @ARGV ) { push @temp_set,shift @ARGV; last if $temp_set[$#temp_set] !~ /^-/ and defined $ARGV[0] and $ARGV[0] =~ /^-/; } return @temp_set; } ##get_next_set #### E:\>232942.pl -a -b FOO BAR -a -b -g BAR FOO -a -g FOO loop 1:ALPHA FOUND.BETA FOUND. loop 2:ALPHA FOUND.BETA FOUND.GAMMA FOUND. loop 3:ALPHA FOUND.GAMMA FOUND. E:\>