my $index2 = -1; foreach (1 .. 3) { $index2 = index($body, "c", $index2 + 1); die "No third 'c'" if $index2 < 0; } #### $body =~ /a/g or die "No first 'a'"; my $index1 = pos($body); # my $index1 = index($body, 'a') + length('a'); #### my $inbetween = substr($body, $index1, $index2 - $index1);