in reply to Re^2: Removing recurring consecutive element
in thread Removing recurring consecutive element

If that's what you want. Add this one line after Skeeve's.
push @str, (split ' ',$tpl->[-1])[2];
Sorry I still don't know if this implementation gives the fastest running time.

Regards,
Edward