my %dispatch = ( '>' => sub { $_[0] > $_[1] }, '<' => sub { $_[0] < $_[1] }, '=='=> sub { $_[0] == $_[1] }, ); # now in loop if ( $dispatch{$sop} ) { # OK so $sop exists, get the right function from # the dispatch hash and call it with the args we want if ( &{$dispatch{$sop}}( $tmpdata[8], $sport ) ) { # yabada } else { # ! yabada } } else { die "Illegal op $sop. Are you trying to hack me?\n"; } # end loop