"A C D" #### /A(.*?)C(.*?)D/ #### "ABICID" #### "A--C-D" #### if ($string =~ $test) { for my $offset (1 .. $#-) { my $start = $-[$offset]; my $len = $+[$offset] - $start; substr($test, $start, $len) = "-" x $len; } # now extract only the matched extent push @hyph_padded_seq, substr($test, $-[0], $+[0] - $-[0]); }