open (PROD,"out.txt"); @array = ; foreach $line (@array){ unless ($line =~/JPG?/){ chomp; } print OUT "$line"; }