in reply to interpolating a variable into an operator

mlhii,
Without putting in a bit of extra effort, string eval is the way to go. This is typically considered evil since it is like an open invitation to let ghosts into the machine - and not all of them are Casper. Here is a contrived way to do the same sort of thing safer, but it is more work:
#!/usr/bin/perl use strict; use warnings; my $eq_op = 'eq'; my $ne_op = 'ne'; my $foo = '1234'; my $bar = 'abcd'; my %compare = ( eq => \&eq_compare, ne => \&ne_compare, ); if ( $compare{ $eq_op }->($foo, $bar) ) { print "$foo and $bar are the same string\n"; } if ( $compare{ $ne_op }->($foo, $bar) ) { print "$foo and $bar are not the same string\n"; } sub eq_compare { return $_[0] eq $_[1] } sub ne_compare { return $_[0] ne $_[1] }

Cheers - L~R

On advice from Corion in a /msg, I removed the ternary operator from the sub's returns as they were not needed. Of course, with subs this small you could make them anonymous as he has. Hmmph - my Casper story is funnier though