equality as a variable



i need to put the equality in an if statement as a variable

($val1, $val2, $comp) = (1,2,"gt");
if ($val1 $comp $val2)
{ print $val1; }
i couldnt find anything in the achives.... if some knows it, please let
me know.. or point me in a direction i can research the method.
thanks

.