# untested my %results; while (my $data = $sth->fetchrow_hashref()) { while (my($k, $v)= each %$data) { push( @{$results{$k}}, $v ); } } # your dataplot should then go like this: @data_to_plot = ( [ @results{qw/dayofweek canning multipack quest/} ] );