# open a file to track all ids my $id_file_name = 'all-ids.txt'; open my $id_fh, $id_file_name or die "opening $id_file_name: $!" my @ids = map { s/\s+$//; $_ } <$id_fh>; close $id_fh or die "closing $id_file_name: $!"; my $n_cols = XXX; # how many columns in "table"? my $places = join ',', ('?') x $n_cols; my $ins = $dbh->prepare( "INSERT INTO table" . " VALUES ( $places )" ); local $/ = undef; foreach my $id ( @ids ) { open my $fh, $id or do { warn "opening $id: $!"; next }; my $str = <$fh>; close $fh or do { warn "closing $id: $!"; next }; my $aref = eval $str; if ( !$aref || $@ ) { warn "$id: eval failed (str='$str')"; next; } $ins->execute( @$aref ); }