my $target_word; for my $idx ( 0..($#arglist-1) ) { if( $arglist[ $idx ] eq '-iL' ) { $target_word = $arglist[ $idx + 1 ]; last; } }