#!/usr/local/bin/perl -w use strict; my $string = "blah text1 you mean something like this? text2 blah blah +"; my $t1 = 'text1'; my $t2 = 'text2'; my $match = $t1 . '(.*?)' . $t2; if ($string =~ m/$match/s) { print $1; }