in reply to [untitled node, ID 41059]

One reason it's so slow is that you're loading the entire database table into your program, when you only need 3 lines! You don't need to do that; since you're using MySQL, you can use the LIMIT directive:
select foo from bar limit 3
What do you want that where clause to do? That matches *any* ID: so you don' t need it. Just eliminate the where clause entirely.

And why are you selecting three columns if you only want one? Just say

select data from frog limit 3
Also you should try using bind_columns and fetch, cause it's faster:
my($data); $sth->bind_columns(\$data); while ($sth->fetch) { print $data; }
If you want to select multiple columns, try this:
my $sth = $dbh->prepare(<<SQL); select id, data from frog limit 3 SQL $sth->execute; my($id, $data); $sth->bind_columns(\$id, \$data); while ($sth->fetch) { print $id, "\t", $data, "\n"; }
(By the way, I took out the error-checking partly for brevity, and partly cause I always use RaiseError).

Check out Tricks with DBI.