my %map = ( ">" => sub { return $_[0] > $_[1] }, "<" => sub { return $_[0] < $_[1] }, # ... ); my $value = 23; my $compare = 24; my $condition = "<"; print test(23, "<", 24); sub test { my ($value, $cond, $compare) = @_; my $func = $map{$cond} or die "No function for $cond"; return $func->($value, $compare) ? "true" : "false"; }