eval { # my code here # for example, a call to whatever subroutine is calling # $ftp->put($my_file) or die return 1; } or do { my $err=$@; # my exception handling code here, uses $err, not $@ }