You can use a hash to keep track of how many times you've seen each occurance and base the name on that. I'm assuming that you want to create unique file names based on the first token on each line? If so, here's a snippet that will do that. It's not your implementation but it should be self explanatory enough for you to adapt it.
#!/usr/bin/perl
use strict;
use warnings;
my %index;
my @data = qw/1 2 3 4 3 4 5 1 11 11 11 11 11 3/;
my $filename;
for (@data) {
if ($index{$_}) {
$filename = $_ . $index{$_};
$index{$_}++;
}
else {
$filename = $_;
$index{$_} = 'a';
}
print "Your filename is $filename.\n";
}
The output was..
Your filename is 1.
Your filename is 2.
Your filename is 3.
Your filename is 4.
Your filename is 3a.
Your filename is 4a.
Your filename is 5.
Your filename is 1a.
Your filename is 11.
Your filename is 11a.
Your filename is 11b.
Your filename is 11c.
Your filename is 11d.
Your filename is 3b.
You'll run into issues if you have more occurances of one token than there are letters in the alphabet though.