What you really want is a hash, not an array.
my %hash = (a1 => 'val 1', a2 => 'val 2', a3 => 'val 3');
my $s1 = 'a2'; # you want to read this from a file?
$hash{$s1} = 'new val 2';
Now, if you still want to use an array for the index names and a different array for its values, well, it's up to you, but you are using the wrong tool for the job.
use strict;
my @str = qw(a1 a2 a3);
my @array;
sub search_ref {
my $s = shift;
my $i = 0;
foreach (@str) {
if ($_ eq $s) {
return \$array[$i];
}
$i++;
}
return undef;
}
my $ref = search_ref('a2');
$$ref = 'new val 2';