my @files = glob( '2005*@*.log' ); die "No files found\n" unless @files; open(OUTPUT, ">output" ) or die "Unable to open output\n$!\n"; foreach my $file (@files) { open( MYFILE, $file ) or die "Unable to open $file\n$!\n"; while () { # parse print OUTPUT $parsed_output; } close (MYFILE) or die "Unable to properly close $file\n$!\n"; } close(OUTPUT);