in reply to Using pattern match

$1 doesn't have a value when you define %triggers. You can postpone the evaluation of your string using a sub:
#!/usr/bin/perl -w use strict; my %triggers = ( 'You are (\\w+).' => sub { "Your status is: $1" }, ); my $buff = "You are fired!"; foreach my $trigger ( keys ( %triggers ) ) { if ( $buff =~ /$trigger/ ) { #print "Memory contents of \$1: $1\n"; print &{$triggers{$trigger}}; } } print "\n";

Replies are listed 'Best First'.
Re^2: Using pattern match
by tceng (Novice) on Aug 10, 2007 at 11:23 UTC
    Thank you very much, akho. It works perfectly now.

    Cheers,

    tceng