sub processContent { # do initial processing ... my $ref; eval { $ref = $x->XMLin(...); return 1; #return from eval only } or do { my $err=$@ || "Something bad happened, but I don't know what!"; print STDERR "Invalid content in file: $@"; # doesn't make sense to continue # in a do {...}, this returns from the enclosing *subroutine* return 0; #FAILURE!!! } print STDERR "\nHash dump:\n"; print STDERR Dumper($ref); # do other stuff with $ref (surrounding individual statements # with eval {...} or do {...} as needed .... return 1; #SUCCESS! }