in reply to Passing a value from a module

One approach is to use die to send the exception (with a message) and blockwise eval to catch it. Example:

{ package foo; sub add { my ($x, $y) = @_; die "not a number\n" unless $x =~ /\d/ and $y =~ /\d/; $x + $y } } # catch any exceptions eval { print "1+2==", foo::add(1, 2); print "a+2==", foo::add("a", 2); }; # handle any exceptions caught by eval if ($@) { push @errors, $@; } # program continues...

Note that the subroutine being in a module doesn't really change things much. Your question is about returning out-of-band data. Using a global variable is one approach, and here I've shown another. These techiques work the same whether the subroutine is in the same package or not.