# Map the column name to the validator code: my %validator = ( P_12MONTHDEMANDQTY => \&validate_number, ... P_DLRUOM => \&validate_p_dlruom, ... ); sub validate_fields { my ($updateval, $colname) = @_; if (! exists $validator{ $colname }) { warn "'$colname' is not a valid column name."; }; my $code = $validator{ $colname }; if (! $code->($updateval, $colname)) { warn "'$updateval' is not a valid value for '$colname'."; } else { warn "'$updateval' is a valid value for '$colname'."; return 1 }; }