foreach(@Dateien) { if($_ =~ /\.txt$/) { open(my $fh,"$_") or die $!; # mach was close $fh; } }