、あなたはこのような何かを探していますか?
use strict;
use warnings;
my $file_pattern = "whatever.you.look.for";
my $file_extension = "\.txt";
opendir(DIR, '/my/directory/') or die("Couldn't open dir");
while(my $name_in = readdir(DIR)) {
next unless($name_in =~ /$file_pattern/);
my ($name_base) = ($name_in =~ /(^.*?)$file_pattern/);
my $name_out1 = $name_base . "outfile1.txt";
my $name_out2 = $name_base . "outfile2.txt";
open(IN, "<", $name_in) or die("Couldn't open $name_in for reading");
open(OUT1, ">", $name_out1) or die("Couldn't open $name_out1 for writing");
open(OUT2, ">", $name_out2) or die("Couldn't open $name_out2 for writing");
while(<IN>) {
# do whatever needs to be done
}
close(IN);
close(OUT2);
close(OUT1);
}
closedir(DIR);
編集:拡張ストリッピングが実装され、入力ファイルハンドルが閉じられ、今すぐテストされました。