#Function inside a package sub test() { ... ... open(FILE,"filename") || return (1,"Error while trying to open the file filename"); .... return (0,UNDEF); } # Main Program my ($result,$err)=test(); Now based on the return value i decide to print the error or take corrective messures