#!/usr/bin/perl # http://perlmonks.org/?node_id=1120387 use strict; use warnings; my $log_dir = '/home/smithc'; my $log_file = "$log_dir/trans.log"; my $trans_dir = '/data/FSA_Retrieval'; # Log handles if ( not open my $loghandle, ">>", $log_file ) { # lexical handle and three argument form of open() # syslog ... # what's this? die "Cannot open file $log_file: $!"; } # maybe instead of opendir ... and readdir ... my @files = grep { -f } glob( "$trans_dir/*OT*" ); foreach my $file (@files) { print STDERR "File: $file\n"; print "$file\n"; open my $fh, "<", $file # same here; lexical file handle and 3-arg-form of open() or die "Cannot open $file: $!"; while ( my $line = <$fh> ) { if (/(7722/|59001/)/ && /.{361}(N|U|C)/) { print; } } close $fh; }