my $data = qq(SELECT word FROM swearwords); my $sth = $dbh->prepare($data); $sth->execute() or die $dbh->errstr; while(my $ref = $sth->fetchrow_arrayref) { push @swearwords, $ref->[0]; }