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