my ($idx) = grep $list[$_] eq '-p', 0..$#list; or die("-p not found\n"); ++$idx < @list or die("Missing value for -p\n"); my $val = $list[$idx];