my $a_ref = \'A'; my $c_ref = \'C'; my $t_ref = \'T'; # etc... # Then storing these values in an array reference: my $base_ref; while ( <$fh> ) { # Get the correct values you need my $nuc_ref = $base eq 'A' ? $a_ref : $base eq 'C' ? $c_ref : $base eq 'G' ? $g_ref : $base eq 'T' ? $t_ref : $n_ref; push @{$base_ref}, $nuc_ref; }