#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $filepath = "OP.txt"; my $olddata = readdt2($filepath); print Dumper($olddata); sub readdt2 { my $ifn = shift; open(my $IFH, "<$ifn") or die "cannot open file $ifn\n"; my $line; my @nt = qw(A C T G); my @ret; my @tmp; for (my $j=0; $j<=$#tmp; $j++) { $ret[$nt[$j]] = []; $line = <$IFH>; chomp($line); @tmp = split(/\s+/,$line); for (my $i=0;$i<=$#tmp;$i++) { $ret[$nt[$j]][$i]= $tmp[$i] +0.0001; } } close($IFH); return(\@ret); }