my $ans = qr/^\Q$answer/; if ( "add" =~ /$ans/ ) { ... } elsif ( "remove" =~ /$ans/ ) { ... }