sub filter_by_Species() # Don't use prototypes unless you NEED them. And even then, you probably don't. open( NEWALIGN, "; # Arggh. Read entire file into an array at once. my @subjects = []; # reference to empty array # nope. Array whose first element is a reference to an empty array #so I produce a hash with key = >gi line of report and value = all lines after until next >gi # I saw no "greater than" in the example data... for (my $i = 0 ; $i/) # again, no "greater than" in the example data... { $current_subject = $resultLine[ $i ]; chomp ($current_subject); push (@subjects, $current_subject); $alignment->{$current_subject} = ""; $alignment->{$current_subject}.$resultLine[ $i ]; } # you never use the %$alignment hash anywhere so why bother? my @elements; my $boolean; # declare variables in the smallest scope possible foreach my $z (@subjects) { chomp $z; # already chomped in previous loop show_Output($boolean, $z, @elements); # boolean ALWAYS equal 0. Why not just pass 0?