Rewrite Pkg, a function at a time, to use the much nicer IFS method of parsing repo files:
IFS="|"
while read Field1 Field2 ... FieldN; do
#stuff with fields - there should be no cuts, greps, seds etc...
done < pkgdbFile
This will make Pkg faster to run, and also easier to maintain.
EDIT: see fixed example below