# Get everything up to D: perl -lwe 'print join " ", map scalar(/./../D/), qw(A B C D E F)' # prints: # 1 2 3 4E0 1 2