open(my $AFILE, '<', $file) || warn "ERROR - Couldn't open $file - $!\n"; while (<$AFILE>) { #call the processing as a subroutine } close $AFILE || warn "ERROR - Couldn't close $AFILE - $!\n";