#!perl use strict; package Whatever; my $password = sub { 'passwd_here' }; sub reveal_pass { print "Authorised: ", $password->(), "\n"; } package main; Whatever::reveal_pass; print "Unauthorised: "; print ref $Whatever::password ? $Whatever::password->() : "no access!\n"; __END__ Authorised: passwd_here Unauthorised: no access!