foreach my $file (readdir DIR) { next unless -f $file; open my $in_fh, '<', $file; my @lines = <$in_fh>; close $in_fh; # call subroutine here }