open TMP, ">$file" || print "Can't open temp file: $!"; my $top = 5; my $cont = 0; my $temp = ''; foreach $line (@cpanel) { my $dont = 0; if ($top > 0) { if ($line =~ /:/i) { $dont = 1; } $top--; } unless ($dont) { $temp .= $line; } } $temp ~= s/(^\s+|\s+$)//gis; print TMP $temp; close TMP;