use strict; use warnings; my $stuff = qr/[^A-Z]*/; my $regex = qr{ A $stuff B $stuff C $stuff D }x; while (my $line = ) { if ($line =~ $regex) { print "Matched: $line"; } } __DATA__ ABhere is intervening textC D A B C, lots of text and numbers and equals and slashes DEFG ABhere IS intervening TEXTC D