sub db_do { my (%attr) = ( RaiseError => '1'); my $dbh = DBI->connect('DBI:mysql:DATABASE:localhost', 'username', 'password', \%attr); my ($dbq) = shift; my @args = @_; my $sth = $dbh->prepare("$dbq"); $sth->execute(@args); my $result; my @results; if ($dbq =~ /select/i) { my @row; while (@row = $sth->fetchrow_array) { push @results, [ @row ]; } $result = \@results; } $sth->finish; $dbh->disconnect; return $result; } Note that this doesn't handle errors as it should yet, but is functional. An example of how I use it would be: my $dbq = qq{ INSERT INTO pagers (ptype,pnum,ppin,enum) VALUES (?,?,?,?) }; my $res = db_do("$dbq", "$ptype", "$pnum", "$ppin", "$enum"); or for a simple select: my $dbq = qq{ SELECT email from email where email = ? }; my $res = db_do("$dbq", "$email");