sub find_between_tags($$$) { # pass me the string to parse, the start tag, and the end tag my $string_to_parse = shift; my $start_tag = shift; my $start_pos = index $stuff, $start_tag; # get string position of start tag return unless $start_pos > -1; # return unless start tag found my $stop_tag = shift; my $stop_pos = index $stuff, $stop_tag; # get string position of end tag $stop_pos > -1 ? # end tag found, return substring return substr $stuff, $start_pos, # return substring $stop_pos - $start_pos + length $stop_tag : # including matching tags return substr $stuff, $start_pos, -1; # return substring to end } print find_between_tags($stuff, "START", "STOP"); #### Benchmark: timing 100000 iterations of mine, original... mine: 4 wallclock secs ( 3.28 usr + 0.00 sys = 3.28 CPU) @ 30534.35/s (n=100000) original: 14 wallclock secs (13.12 usr + 0.00 sys = 13.12 CPU) @ 7622.53/s (n=100000)