use strict; use warnings; # declare variables my @column = (); my $y; my %hash; my $count; my $range = 3; # open the file open(INFILE,"<","my_column_file.txt") or die("Couldn't open the file\n"); while () { print "\n"; #separate the elements in each row with a newline for ($y=0; $y < 3; $y++){ # from the first to the last field (ie field/column 3) my ($field) = (split)[$y]; # extract fields/ columns from the data push @column, $field; # store all the field values in an a array #count the consecutive r's --> all those common to a row #(i.e.if a sinlge specified column misses an r at that row don't cont it)! while ($field =~ /(r+)/g) { my $new_count = $count++; print "$new_count\n"; } print pop@column; # print from the array, each time removing the printed element (avoiding repetition) print "\n"; # print each element in a new line } } #### 0 a b h 1 - r z 3 u - u 4 r x r 5 r t r 6 r r r 7 r r r 8 r r r