my $store = $schema->resultset('Items'); $store = restrict_to_department( $store, $department ) if $department; $store = restrict_to_seller( $store, $seller ) if $seller; print format_top_ten_items( $store ); # doesn't care whether $store is restricted sub restrict_to_department { $_[0]->search({ 'department.name' => $_[1] }, { join => "departments" }); }