sub all_segments { my $self = shift; return $self->_gapfill_engine('all'); } sub all_gapfillers { my $self = shift; return $self->_gapfill_engine('gap'); } sub _gapfill_engine { my $self = shift; my $mode = shift; ... # foreach and if loops (next stage in refactoring) # do one thing if $mode eq 'all' # do another thing if $mode eq 'gap' return \@segments; }