#!/usr/bin/perl use strict; my $log_dir = '/home/user1'; my $trans_dir = '/data/directoy1'; my $file; my $participant; my @files; my $line; if (!open(LOG, " >>$log_dir/trans.log")) { syslog("Warning:","Cannot open log file called: $log_dir/trans.log"); die "Cannot open the file $log_dir/trans.log, $!"; } undef (@files); opendir(DIR,$trans_dir); my @files = grep { /(OT)/ # Filename contains OT && -f "$trans_dir/$_" # and is a file } readdir(DIR); foreach $file (@files) { print STDERR "File: $file\n"; open(FILE,"<$trans_dir/$file") or die "Cannot open $file"; print "$file\n"; for $line () { ($participant) =~/(.....)\//; print "$participant"; close (FILE); } } closedir(DIR);