use strict; use warnings; use DBI; use XML::Simple; my $dbh = DBI->connect( ... ); my $xml = XMLin(\*DATA, keyattr => 'document'); insert($_) for @{$xml->{document}}; sub insert { my $hash = shift; my $sth = $dbh->prepare( 'insert into bar (' . join(',', keys %$hash) . ') values (' . join(',',map '?',keys %$hash) . ')' ); $sth->execute(values %$hash); } __DATA__ 1 1 2 Swedish Foo http://www.foo.se/bar/ International 0 0 3 Swedish Bar http://www.bar.se/baz/ National #### use DBI::Wrap; use XML::Simple; my $dbh = DBI::Wrap->new( ... ); $dbh->table('hacker'); my $xml = XMLin(\*DATA, keyattr => 'document'); $dbh->insert(Values => $_) for @{$xml->{document}}; __DATA__ (insert data from above snippet)