I'm assuming that the "a[0] -", "a[1] -", and "a[2] -" prefixes on each line of your sample input are not part of the contents of your array, but rather, your demonstration of what element index of the array is being represented, and that the part that comes after that is the contents of your array. Also you were unclear in your explanation on what is supposed to happen with the line number portion of the string contained in each element of the array. Because it was unclear, I'm leaving it out of my demonstrated solution.
use strict;
use warnings;
my @array = <DATA>;
foreach my $element (@array) {
chomp $element;
my ($fname, $line_number, $content) = split /\s*:\s*/, $element;
open my $outfh, '>>', $fname
or die "Cannot open $fname: $!\n";
print $outfh $content; # You didn't tell us what is supposed to ha
+ppen with $line_number.
close $outfh or die "Couldn't close $fname after writing: $!\n";
}
__DATA__
tests/right/case1: 12 : //comment
tests/right/case1: 13 : //comment
test/right/case3: 5 : //comment
The standard behavior of the >> open mode is to create if the file does not exist, and append if it does, so you really don't need to worry about whether you've seen the file before.
If the code in this answer is difficult to follow I encourage you to spend some time with the following Perl documentation, which comes with any full installation of Perl.