open(my $fh1, ">>", "outputcontrol.txt"); open(my $fh2, ">>", "outputoutput.txt"); while ( <> ) { my $count = ($_ =~ y/x//); print "$count \n"; # print $_; if ( $count != $delim_amnt_per_line ) { print fh1 $_; } my ($prefix) = substr $_, 0, 7; next if $seen{$prefix}++; print fh2 $_; }