my $p = 'This is an anchor and these are another couple.'; $prefixes = ''; while ($p =~ s/(]*>)//) { $prefixes .= $1; } $p = "$prefixes$p";