#!/usr/bin/perl use Foo; use strict; use warnings; sub call (&); call { Foo::foo(); }; if ($@) { warn "foo reported: '$@'\n"; } ## subs # sub call (&) { my $coderef = shift; my $message; open my $fh , '>&', \*STDERR; close STDERR; open STDERR, '>', \$message; $coderef->(); open STDERR, ">&", $fh; $@ = $message; } __END__ foo reported: 'blorf! at Foo.pm line 3. '