#/usr/bin/perl #pm1216404 use warnings; use strict; use 5.010; # for // #my @status = map {chomp; $_} ; # use the chomp to get rid of the newlines from the DATA right away my @status = sort { $a <=> $b } map {chomp; $_} ; # edit 2 = sort the status after you read and map it, so now my %unmap = map { $status[$_] => $_ } 0..$#status; # makes a hash of $unmap{value} = index pairs # use Data::Dumper; print Dumper \@status, \%unmap; $|++; foreach my $current ( @status ) { # edit 2 = remove the sort here, because it's sorted above my $idx = $unmap{$current}; my $ni = defined $idx ? $idx+1 : undef; my $next = defined $ni ? $status[$ni] : undef; printf "current=%d, current's index=%s, next idx=%d, next value=%s\n", $current, $idx//'', $ni//'', $next//''; } __DATA__ 11673326 11673329 11673325 11673330 11673321 11673335