table stats ( jobid INT, try INT, item VARCHAR(255), value VARCHAR(255), # or maybe TEXT or equivalent PRIMARY KEY (jobid, try) ); #### select item, value from stats where jobid=273118 and try=1 #### select owner, count(*) as n from stats where try=1 group by owner order by n #### foreach (keys %hash) { $dbi->do('insert into stats (jobid,try,item,value) (?,?,?,?)',$jobid, $try, $_, $hash{$_}); }