# Inefficient! my $s = 'ABCDEFGHIJKLMNOPCDEFQRST'; my $first = 'C'; my $middle = 'DE'; my $last = 'F'; my $spos = -1; for (;;) { $spos = index($s, $first, $spos+1); last if $spos < 0; my $epos = $spos + length($first) - 1; for (;;) { $epos = index($s, $last, $epos+1); last if $epos < 0; my $len = $epos - $spos + 1 - length($first) - length($last); if (substr($s, $spos+1, $len) eq $middle) { print("Match at $spos\n"); } } }