#!/usr/bin/perl use strict; use warnings; use Data::Dumper; sub getn_split { return +(split //, $_[0])[$_[1]-1]; } my $file = 'data.txt'; my @array; if (open(my $fh, '<', $file)) { while (<$fh>) { chomp; push @array, getn_split($_, 10); } } else { warn "Could not open file '$file' $!\n"; } print Dumper \@array; __END__ $ cat data.txt ACATCACCTCCCACAACGAGGACTACACCATCGTGGAACA ACATCACCTACCACAACGAGGACTACACCATCGTGGAACA $ perl test.pl $VAR1 = [ 'C', 'A' ];