#! perl -sw use Data::Dumper; use strict; local $\=$/; =pod Note! This is a comment only!! my %patterns; open(PFILE, "whatpattern.txt")|| die "Cannot open whatpattern.txt file"; while () { chomp; next unless $_; my @tags = split /; |:/; my $key = shift @tags; $patterns{$key} = \@tags; } open(TESTFILE, "alltestfile")|| die "Cannot open alltestfile"; =cut my %patterns = ( '/WRB1/JJ1/VBZ1/NP1/IN1/NP2' => '/NP1/VBZ1(so)/JJ1 : /NP1/IN1/NP2/VBZ1(really)/JJ1', '/WP/NP1/VB1/VBN1/PP1' => '/PP1/PP2/NP1(are)/VB1', ); while(defined(my $question=)) { my @qkeys = $question =~ m!(/[A-Z0-9]+)!g; my @qvalues = $question =~ m!(.*?)(?:/[A-Z0-9]+\s+)!g; my %questionlookup; @questionlookup{@qkeys} = @qvalues; my $key = join'',@qkeys; print $question."\n\n"; if (my $answer = $patterns{$key}) { #! You had a syntax error here--------------------v !!!!!!!!!!! #! $answer =~ s!\s*$_\s*! $questionlookup{$_} !g for qkeys %questionlookup; $answer =~ s!\s*$_\s*! $questionlookup{$_} !g for keys %questionlookup; $answer =~ s/\:/\n\n/g; print $answer; } else { print "No Match\n"; } } __DATA__ How/WRB1 hot/JJ1 is/VBZ1 the core/NP1 of/IN1 the earth/NP2 ?/