my $match = sub { return substr($_[0], 0, 3) eq substr($_[1], 0, 3); }; print $match->('aaaa','aaab'); #### myset($match, @words); sub myset { my $match = shift; # Do whatever set algorithm here, # using $match to compare words }