in reply to Extra Space Issue

How could I remove any extra spaces before they reach the line my $array_ref = $sth->fetchall_arrayref(); or any other solution to prevent that.

If it is true that you cannot modify the fetchloop processing -- pity, because that code wants to be refactored and would be an easy place to handle data normalization -- then you might normalize in the DB engine itself with $sql.

Try the ANSI SQL SUBSTRING() or DBMS-specific TRIM/RTRIM(). Or, as Fletch suggested, clean up your data before you store it.

-Mike

Updated: More, better grammar. :)