Script for updating an Oracle database
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";
   }
}