#!/usr/local/bin/perl -w use strict; my $string = "blah text1 you mean more like this? text2 blah"; my $t1 = 't(e*x+t)1'; my $t2 = 't[ex]*t?2'; my $match = qr/\Q$t1\E(.*?)\Q$t2/; print "no match\n" unless $string =~ m/$match/s;