#!/usr/bin/env perl use strict; use warnings; use Carp; use English; # Do some work foreach my $file ( glob('/root/fd/fg/*.txt') ) { next if(-f $file . '.done'); # Skip if '*.done' file exists open(my $ifh, '<', $file) or croak($ERRNO); my $ad; my @rt; while((my $line = <$ifh>)) { if($line =~ m/ad/) { ($line =~ tr/a-z,=//d ) ; $ad = $line ; } if ($line =~ m/rt /){ ($line =~ tr/a-z,=//d) ; push (@rt , $line); } } close $ifh; # Need to close fille after working on it. open(my $ofh, '>', $file . '.done') or croak($ERRNO); # Create '*.done' file close($ofh); } # Cleanup foreach my $file ( glob('/root/fd/fg/*.txt.done') ) { my $realfname = $file; $realfname =~ s/\.done$//; if(!-f $realfname) { unlink $file; } }