$_ = ''; if ( open( INPUT, "<", $file )) { $/ = undef; $_ = ; close INPUT; } if ( ! $_ ) { warn "No data found in $file\n"; next; } # now it will be easier to categorize/parse $_ ...