use strict; use warnings; my $obj = bless {indent => '...'}; for my $suffix (qw(hello world)) { my $func = $obj->can("print_$suffix"); next if ! $func; $func->($obj, " (suffix was $suffix)"); } sub print_hello { my ($self, $suffix) = @_; print "$self->{indent}hello$suffix\n"; } sub print_world { my ($self, $suffix) = @_; print "$self->{indent}world$suffix\n"; }