#!/ms/dist/perl5/bin/perl5.10 use Tie::File; use strict; use warnings; sub process{ my @lines; my $filename = shift; if(-f $filename){ print $filename."\n"; tie(@lines, 'Tie::File', $filename) or die; for (my $i=0;$i<scalar(@lines);$i++){ if($lines[$i] =~ /use warnings/ && $lines[$i+1]!~ /use MyPlant::Dependencies/){ @lines = ((@lines[0 .. $i]),"use MyPlant::Dependencies;\n",(@lines[$i+1 .. @lines])); print $lines[$i]."\n"; print $lines[$i+1]."\n"; print $lines[$i+2]."\n"; } } untie(@lines); } } opendir(DH,".") or die "Can't open: $!\n"; my @filelist = grep /pl$/, readdir(DH); foreach my $file (@filelist){ next if($file eq '.' || $file eq '..' ||$file eq 'test.pl'); process($file); }