Script for updating an Oracle database I have the following piece of Perl script for updating an Oracle database. It's working perfectly fine, but I want to know how I can simplify this script.

use DBI;
my $dbh;
my $bad_form = "text.txt";

open (OUT, $bad_form) or die "Could not open $bad_form";
while (&lt;OUT&gt;){
   chomp $_;
   my ($item_id, $description, $form_id_1, $form_id_3) = split(/\|/, $_);

   my $new_form_id_1 = form_1($form_id_1);
   my $new_form_id_3 = form_3($form_id_3);

   if ( $new_form_id_1 ne 'null' ){
        my $sql = "update item_table set form_id_1 = '$new_form_id_1' where item_id = '$item_id'";
        my $item = $dbh-&gt;prepare($sql) or (log_error("Couldn't prepare statement: " . $dbh-&gt;errstr) and return 2);
        $item-&gt;execute() or (log_error("Couldn't execute statement: " . $item-&gt;errstr) and return 2);
   }else{
        $form_id_1 = "correct value";
        $new_form_id_1 = "no updated";
}

   if ( $new_form_id_3 ne 'null' ){
        my $sql = "update item_table set form_id_3 = '$new_form_id_3' where item_id = '$item_id'";
        my $item = $dbh-&gt;prepare($sql) or (log_error("Couldn't prepare statement: " . $dbh-&gt;errstr) and return 2);
        $item-&gt;execute() or (log_error("Couldn't execute statement: " . $item-&gt;errstr) and return 2);

   }else{
        $form_id_3 = "correct value";
        $new_form_id_3 = "no updated";
   }
}
Some basic refactoring, and using ? placeholders in sql queries,

use strict;
use warnings;
use DBI;
my $dbh;
my $bad_form = "text.txt";

sub prepare_execute {
    my ($sql, $values, $dbh) = @_;

    my $item = $dbh-&gt;prepare($sql) or do {
        log_error("Couldn't prepare statement: " . $dbh-&gt;errstr);
        die;
    };
    $item-&gt;execute(@$values) or do {
        log_error("Couldn't execute statement: " . $item-&gt;errstr);
        die;
    };
    return 1;
}

open (my $OUT, "&lt;", $bad_form) or die "$! $bad_form";
while (&lt;$OUT&gt;) {
   chomp $_;
   my ($item_id, $description, $form_id_1, $form_id_3) = split(/\|/, $_);

   my $new_form_id_1 = form_1($form_id_1);
   my $new_form_id_3 = form_3($form_id_3);

   if ( $new_form_id_1 ne 'null' ){
        my $sql = "update item_table set form_id_1 =? where item_id =?";
        eval { prepare_execute($sql, [$new_form_id_1, $item_id], $dbh) }
          or return 2;
   }
   else {
        $form_id_1 = "correct value";
        $new_form_id_1 = "no updated";
    }

   if ( $new_form_id_3 ne 'null' ) {
        my $sql = "update item_table set form_id_3 =? where item_id =?";
        eval { prepare_execute($sql, [$new_form_id_3, $item_id], $dbh) }
          or return 2;
   }
   else {
        $form_id_3 = "correct value";
        $new_form_id_3 = "no updated";
   }
}