in reply to Performance optimization question
I'd probably try a regex only, but I'm not sure it will improve matters. This code assumes /reg exp/ does not match | characters and that $string doesn't start with a |:
my @results = $string =~ /(reg exp)(?:\||$)/g;
|
|---|