$/ = ... # whatever my @posts = ; # read all posts in at once and assign # each to an array element. my @keep_posts; for(my $index = 0; $index < @posts; $index++) { unless(defined($cgi->param("box$index")) { push @keep_posts, $posts[$index]; } } # open file... print all the kept ones out. print NEW_FILE join("\n\n\n", @keep_posts);