#!/usr/bin/perl use warnings; use strict; use Data::Dumper; #open initial file open FILE, "graph.txt" or die "Error with original file: $!"; #open empty file to write to #open NEWFILE, ">output.txt" or die "Error with output file: $!"; #Get array with lines of file my @line_array = ; #reduce array to content info only shift(@line_array); pop(@line_array); #initialize item array and something to hold it during loop our @item_array; our @hold_array; #convert each edge string to an array, push it onto item_array for (my $i = 0; $i < scalar(@line_array); $i++) { our $line = $line_array[$i]; @hold_array = split(/\s/, $line); push(@item_array, \@hold_array); } print Dumper @item_array;