my $baseDir = "test"; ... opendir(DIR, $baseDir) or die "Error: couldn't open dir '$baseDir': $!\n"; my @datei = grep { -f "$baseDir/$_" and /\.jpe?g$/ } readdir(DIR); ... my $img = $fenster->Photo(-file => "$baseDir/$bilder[$j]", -format => "JPEG", );