use strict; use warnings; use feature 'say'; my %operators = ( '>' => sub { $_[0] > $_[1] }, '==' => sub { $_[0] == $_[1] }); sub test { my ($op, $left, $right) = @_; die "Unknown operator: $op" unless exists $operators{$op}; say "$left $op $right" and return if $operators{$op}($left, $right); say "$right $op $left" if $operators{$op}($right, $left); } test "==", 1, 1; test ">", 2, 3; test ">", 4, 5; test "<", 6, 7; __DATA__ 1 == 1 3 > 2 5 > 4 Unknown operator: < at pm_1208722.pl line 12.