use vars qw( $error ); sub do_lots { $error = 0; # assume things are correct unless told otherwise my %hash = @_; %hash = mangle_once(%hash); return $error if $error; %hash = mangle_twice(%hash); return $error if $error; # ... as necessary }