while ($sqlSuccess == 0) { eval { ... }; if ($@) { my $errString = $@; $@ = ''; # <-- here print $fileHandle "caught error $errString\n"; ... } }