use strict; use warnings; my $queryCount=0; my $answeredCount=0; my %connected=(); while(<>) { print; chomp($_); if (/q (\d+) (\d+)/) { $answeredCount++ if ( defined $connected{$1} and $connected{$2}); $queryCount++; } elsif (/c (\d+) (\d+)/) { $connected{$1}=1; $connected{$2}=1; } } print "$answeredCount,".($queryCount-$answeredCount)."\n";