my @datasets; for my $i (...) { .... push @datasets, Chart::Gnuplot::DataSet->new(...); $chart->plot2d(@datasets); }