my $ref; eval { $ref = $x->XMLin(...); print STDERR "\nHash dump:\n"; print STDERR Dumper($ref); # this only returns from the eval, not the function #make sure we only end up in ... or do {...} if we are dying return 1; } or do { #sometimes you can die but $@ is '' or undefined!!! my $err=$@ || "Something bad happened, but I don't know what!"; print STDERR "Invalid content in file: $@"; }