Well. Probably you are looking the wrong way. If your programm directly connects to DB using DBI or alike, then DBI takes care of all necessary optimizations. Your attempts to convert strings to numbers just make system less efficient. If your programm simply passes data from one server to another, where another program picks it up, then again it makes sense simply take the text, zip it (or bzip2 it :) and then copy to
remote. Probably rsync with option -z would be best for this.
The point is. Conversion of perl variable from text to number does not add any compactness.
The other point is. Iterating over elements of array using foreach is faster.