#Dependencies (relations and arguments): if ($category_id eq "all") { my @lines = split ("\n",$sentblock); ##Split by a newline foreach my $line (@lines) { my @matches; next unless ($line =~ /\b$verbform\b/i); ##Ensure dependency contains searchword ##NEXT LINE IS DIFFERENCE: next unless ($line =~ /subj\w*\(|obj\w*\(|prep\w*\(|xcomp\w*\(|agent\w*\(|purpcl\w*\(|conj_and\w*\(/); ##Ensure dependency only contains desired grammar relations next unless ($line =~ /(\w+)\((\w+)\-\d+\,\s(\w+)\-\d+\)/); ##Ensure dependency is a dependency AND get info from it $grammar_relation = $1; $argument1 = $2; $argument2 = $3; next if ($argument1 eq $argument2); ##Ensure 1st and 2nd argument aren't the same next if ($grammar_relation =~ /xcomp/i and $argument2 !~ /\b$verbform\b/i); ##Ensure for xcomp the searchword is the 2nd argument next if ($argument1 =~ /^\S$/ or $argument2 =~ /^\S$/); ##Exclude if argument is only 1 character push(@matches, $chapternumber, $sentencenumber, $sentence, $grammar_relation, $argument1, $argument2); ##All here, so either all get pushed or none (no holes in array) push @all_matches, \@matches; } } elsif ($category_id eq "subj") { my @lines = split ("\n",$sentblock); ##Split by a newline foreach my $line (@lines) { my @matches; next unless ($line =~ /\b$verbform\b/i); ##Ensure dependency contains searchword next unless ($line =~ /subj\w*\(|agent\w*\(/); ##Ensure dependency only contains desired grammar relations next unless ($line =~ /(\w+)\((\w+)\-\d+\,\s(\w+)\-\d+\)/); ##Ensure dependency is a dependency AND get info from it $grammar_relation = $1; $argument1 = $2; $argument2 = $3; next if ($argument1 eq $argument2); ##Ensure 1st and 2nd argument aren't the same next if ($argument1 =~ /^\S$/ or $argument2 =~ /^\S$/); ##Exclude if argument is only 1 character push(@matches, $chapternumber, $sentencenumber, $sentence, $grammar_relation, $argument1, $argument2); push @all_matches, \@matches; } } ...etc... for a few more elsifs #To make the if elsif into subroutine: Name:get_all_matches Pass In: ($sentblock, $verbform, $chapternumber, $sentencenumber, $sentence) Return: @allmatches (if needed, return reference)