for(@str) { /^(\w{2}_[a-z\d]+|[a-z\d]+(?=_))/i and print $1, $/; }