A subroutine that generates subroutines based on some input values.
examples/references/incrementer.pl
#!/usr/bin/perl
use strict;
use warnings;

sub incrementer {
    my $old = $_[0];
    $_[0] += $_[1];
    return $old;
}

my $x = 23;
my $old = incrementer($x, 19);
print "$old  $x\n"; # 23  42

sub incrementer_23 {
    my $inc = 23;
    my $old = $_[0];
    $_[0] += $inc;
    return $old;
}


examples/references/incrementer-generator.pl
#!/usr/bin/perl
use strict;
use warnings;

sub incrementer_generator {
    my ($inc) = @_;

    return sub {
        my $old = $_[0];
        $_[0] += $inc;
        return $old;
    }
}

my $inc19 = incrementer_generator(19);

my $x = 23;
my $old_value = $inc19->($x);
print "$x\n";
print "old after inc19: $old_value\n";


my $inc5 = incrementer_generator(5);
print "old after inc5: " . $inc5->($x) . "\n";
print "$x\n";

my $prev_value = $inc19->($x);
print "old after inc19: $prev_value\n";
print "$x\n";

Output:

examples/references/incrementer-generator.out
42
old after inc19: 23
old after inc5: 42
47
old after inc19: 47
66