Perl 5.8.8 (test.pl) use strict; use warnings; use DBI; use Encode; use utf8; my $filename = 'test.xml'; my $data; open (my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; while (my $row = <$fh>){ chomp $row; print "$row " . ( utf8::is_utf8 ( $row ) + 0) . "\n"; # prints: Sustitución1 $data = $row; print "$data " . ( utf8::is_utf8 ( $data ) + 0) . "\n"; # prints: Sustitución1 } ###### my $sql = "INSERT INTO testTable (a,b,c,es) VALUES (?,?,?,?)"; # USE EITHER THIS LINE OF CODE OR ... #my @array = qw(3 2 1 Sustitución); # THESE 2 LINES OF CODE my @array = (3, 2, 1); push @array, $data; print $array[3] . ( utf8::is_utf8 ( $array[3] ) + 0) . "\n"; # prints: Sustitución1 my $connect = "DBI:mysql:$dbname"; my $dbh = DBI->connect($connect, $dbuser, $dbpass, {mysql_enable_utf8 => 1, 'RaiseError'=>1, 'AutoCommit'=>0, 'PrintError'=>1}) or die "Error: $DBI::errstr\n"; my %query = ( sql => $sql, dbh => $dbh, data => \@array ); ### # call function that tests execute(@array) runQuery(\%query,1); sub runQuery{ my %args = %{$_[0]}; my $commit = $_[1]; my $sth = $args{dbh}->prepare($args{sql}); # execute the query eval{ $sth->execute(@{$args{data}}); } or do{ my $error = DBI->errstr; $args{dbh}->rollback(); }; # commit when we are told if($commit){ # test the commit - if all went well, this day was inserted successfully! eval{ my $rc = $args{dbh}->commit(); # commit to local database, $dbh2 print "$rc = successful commit!\n"; } or do{ my $error = DBI->errstr; $args{dbh}->rollback(); # rollback local database, $dbh2 die "Rollback - There has been a problem! $error\n"; }; } } # end sub runQuery