#!/usr/bin/perl use File::Find; my $old_flag = 0; find ( { wanted => \&process, preprocess => \&preprocess, postprocess => \&postprocess }, '/home/greg/mydir' ); sub process { print "Processing\n"; if (/.*\.old$/) { $old_flag = 1; } } sub preprocess { print "Pre-Processing\n"; my @file_list = @_; $old_flag = 0; return @file_list; } sub postprocess { print "Post-Processing\n"; my $old_CPB = "CPB.old"; my $new_CPB = "CPB"; if ($old_flag == 1) { if (rename $new_CPB, $old_CPB) { open IN, $old_CPB or die "Unable to open input CPB: $!"; open OUT, ">$new_CPB" or die "Unable to open output CPB: $!"; while () { chomp; if (/^cat.*/) { print OUT "cat\t/kat/src/all/bld_pipe.4go \\\n"; s/^cat\t/\t/; } print OUT "$_\n"; } } else { #not found return; } } close IN; close OUT; }