my $string = 'this is a test /test123?'; my $start = "\Q/\E"; my $end = "\Q?\E"; my $regexp = qr/$start(.*)$end/; warn $1 if $string =~ $regexp ;