# Same thing, but built dynamically. my $re = join '[^A-Z]*', split //, 'ABCD'; $s =~ /$re/;