sub cleanthefile { my @filehandles; # Keep varibles in same order as they were passed to the sub-routine my ( $removeq, $sourcefile, $tempfile, $backup ) = @_; # Keep a dedicated backup of CC_print.printers if (-e "$_[3]" ) { system ( "cp -R $_[1] $_[3]" ); # create a temporary file if ( !-e "$_[1]") { system("touch $_[2]"); } # extract lines from $sourcefile which do NOT have the string to remove # note that the \' inserts ticks so that strings with spaces can work, too if ( -e "$_[1]") { # system ("cat $sourcefile \| grep -v $removeq $sourcefile > $tempfile"); system ( "grep -v $_[0] $_[1] > $_[2]" ); sleep 1; print "Waiting to unlink..\n"; # delete source file, then rename working file unlink($_[1]); rename( $_[2], $_[1] ); system("rm -rf $_[2]"); } } else { system("touch $_[3]"); system("cp -R $_[1] $_[3]"); } }