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");