# ... descend into directory /var/log/accounts/... my $directory = '/var/log/accounts/'; opendir DIR, $directory or die $!.$/; # ... several hundred files ... my @files = readdir(DIR); closedir DIR or warn $!.$/; ... go round in a loop until no more files ... for my $file (@files) { # ... open it ... open FILE, $file or die $!.$/; # ... into variables ... username,domain,email,service ... my ( $username, $domain, $email, $service ) = split /,/, ; # ... read the contents ... # run the code that i have created #your code here! # ... close that file, ... close FILE or warn $!.$/; # ... delete that file ... unlink $file; } =cut