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