#!/usr/local/bin/perl use strict; use warnings; open (FILE, "<:utf8", "outputps_scan_chr1_.out"); my @lines = ; my @uniq = (); my @waste = (); my %seen = (); foreach my $line (@lines) { my $pat = $line =~ m/^LOC_Os0[1-7]g[0-9]*.[0-9]\s/; if (!$seen{$pat}++) { push (@uniq, $line); my $new_uniq++; } else { push (@wastee, $line); } open (MYFILE, ">:utf8", "data.txt"); print MYFILE @uniq; open (WASTE, ">:utf8", "waste.txt"); print WASTE @waste; } close (MYFILE); close (WASTE); close (FILE);