# Get everything up to and D: perl -lwe 'print join " ", grep scalar(/./../D/), qw(A B C D E F)' # prints: # A B C D E F