if ($a) { foreach $a (@a) { print $a; discover ($a); } } if ($b) { print $b: discover ($b); } sub discover { ## do lots of repetitive stuff }