sub myopen { my ($file, $mode, $locktype) = @_; #open the file...for the sake of brevity #I'll not include the mode logic here if (open(my $fh, "$file")){ print "Opened $file successfully.\n"; #lock the file #do whatever else needs to be done return $fh; } else { warn "Can't open: $!\n"; } }