sub open_dbi { my $db_user = $DBuser; my $db_password = $DBpassword; my $DBName = 'db'; my $dbh = DSBI->connect("dbi:mysql:DBName:$IP","$db_user","db_password"; return $dbh; } This part writes the sql command to the table: sub write_db { $SQLCommand = "{SQL command}"; my $sth = $dbh->prepare("$SQLCommand"); $sth->execute; }