my $list_file=$ARGV[0]; my $outdir=$ARGV[1]; my $file_name; my $text; open LIST,$list_file; chomp(my $path=); while($file_name=) { chomp $file_name; local $/=undef; open INFILE,catfile($path,$file_name); $text= close INFILE; my $string=function1($text); function2($text); my $bindex=index($text,""); $text=substr($text,0,$bindex). "\n". $string."\n". "\n". substr($text,$bindex); open OUT,'>'.catfile($outdir,$file_name); print OUT $text; close OUT; }