use strict; use Cwd; use IO::File; my $gpl_text_file = new IO::File("gpl_text.txt", "r") or die $!; my @gpl_text = <$gpl_text_file>; opendir(DIR, "syntacticanalysis"); my @files = readdir(DIR); for my $file (@files) { next unless ($file =~ m/java$/); my $full_path = "syntacticanalysis/$file"; my $new_full_path = $full_path.".new"; my $fh = new IO::File($full_path, "r"); my $new_file = new IO::File($new_full_path, "w") or die $!; foreach my $line (@gpl_text) { print $new_file $line; } print $new_file "\n\n"; while(my $line = $fh->getline) { print $new_file $line; } $fh->close; $new_file->close; `rm $full_path`; `mv $new_full_path $full_path`; } closedir(DIR);