in reply to Replacing SQL with perl

It really does come down to "it depends on what you are doing." You really have to know your database and your perl very well. In general, I leave most things to the database if possible, and use the SQL to return the smallest, most refined result set back to the script as possible. One thing that I almost always do with perl however, is sorting... SQL cannot touch some of perl's beauty in sorting:
my $unsorted = $dbh->selectall_arrayref($FOOSQL) or die "Fooey, foo failed ($FOOSQL) $DBI::errstr\n"; for ( sort { $Q::SortBy == 1 ? ($a->[1] cmp $b->[1] or $a->[4] cmp $b->[4] or $a->[2] cmp $b->[2] +) : $Q::SortBy == 2 ? ($a->[1] cmp $b->[1] or $a->[2] cmp $b->[2]) : ($b->[3] <=> $a->[3] or $a->[2] cmp $b->[2]) } map {[$_, lc $_->[5], substr($_->[4],3,3), int $_->[1], lc $_->[3]]} @ +$unsorted) { ## Do something with $_ here... }