my $data = qq(SELECT word FROM swears); my $sth = $dbh->prepare($data); $sth->execute() or die $dbh->errstr; while(my $ref = $sth->fetchrow_arrayref) { push @swearwords, $ref->[0]; } #### while ($sth->fetch) { $text =~ s/$_/****/ foreach @swearwords;