my $source = 'VM'; my $COB = '20080605'; my $regex = qr /^$source.*$COB/; while () { if (/$regex/) { print "Matched $_"; } }