in reply to passing a variable from one subroutine to another

A possible way to do so is to pass $error on to log_action a second parameter. That would be:
sub exec{ #... &log_action('error',$error); } sub log_action{ my $i = shift; #get first parameter my $error = shift; get second parameter # note that this $error here is not the same variable but has the same + value! #do whatever with it... }

You should also consult your Camel Book on Subroutines.

Hope this helps,
C-Keen