perl -lwe'my @a=qw(A B C D E F); print for grep ($_==1) .. ($a[$_]=~/D/), 0..$#a'