#!/usr/bin/perl use strict; use warnings; BEGIN { $|=1; } END { print "not ok\n" unless $::tiestderrloaded; } BEGIN { print "Loading Tie::STDERR\n"; } use Tie::STDERR \&HandleError; $::tiestderrloaded = 1; print "Before\n"; if ($@) { die "...."; } print "After\n"; use Tie::STDERR undef; sub HandleError { my ($error) = @_; &SomeActivity('0',$error); } sub SomeActivity { my ($rc, $error) = @_; print $rc . "\n" . $error; }