my $storage_dir = "C:/Stuff/"; foreach my $category qw( abc def ghi ) { foreach my $subcategory qw( this that ){ foreach my $year ( 1..3) { my $file = sprintf("%s_%s_02d.csv", $category, $subcategory,$year); my $path = $storage_dir.$file; # now do something with the file, i.e. generate your plot command do_plot( $path ); } } } sub do_plot { my $path - shift; ### do the actual plotting here }