jonnyfolk has asked for the wisdom of the Perl Monks concerning the following question:

I have several statements accessing a hash of arrays, eg:
while ( (my $key, my $value) = each %partners) { if ($item eq $key) { ($partners,$email,$nickname,$realname,$postcode,$phone) = +(@$value); push (@allmembers, $item); my @partners_split = split / /, $partners; push (@allmembers, @partners_split); } }
while ( (my $key, my $value) = each %partners) { if ($item eq $key) { ($partners,$email,$nickname,$realname,$postcode,$phone) = (@$v +alue); ##another, different action; } }
These are identical apart from the action that takes place within, and so I would like to create a subroutine containing a variable representing the action, which I can define before calling the subroutine.

Could anyone advise me how I could do this?

Update: I noticed that the actions in both examples were very similar so I changed the second to a comment to avoid confusion...