package Mypackage; use Config::Simple; use Mail::IMAPClient; use strict; sub new { my ($class) = @_; bless {}, $class; } sub load_config { my ($self, %a) = @_; return new Config::Simple("$a{cfg}"); } sub connect_to_imaphost { my ($self, %a) = @_; return Mail::IMAPClient->new( Server => $a{IMAP_HOST}, User => $a{EM_UNAME}, Password => $a{EM_PWD}, Uid => 0, Debug => $a{DEBUGGING}, ); } sub other_methods... {} ### and then, in my script... use Mypackage; my $a = Mypackage->new(); # $a has all the methods of Mypackage $f->load_config(cfg => "my.conf")->import_names(); # this works and imports all the config vars my $imap = $a->connect_to_imaphost( server => $IMAP_HOST, user => $EM_UNAME, password => $EM_PWD, debug => $DEBUGGING, ); my $msg_count = $imap->message_count("$INBOX"); # the vars above have been imported via Config::Simple # the above, however, fails with the following ##Not connected at ./myscript.pl line 48 ##Error sending '1 STATUS inbox (MESSAGES)' to IMAP: at ./myscript.pl line 48