#!usr/bin/perl use warnings; use strict; use Data::Dumper; use List::Pairwise qw(mapp grepp); ##need to install this module my @ary = qw(AirDefense 2 Mobile-N-Site 4 Owl 6 undef 8); my %hash = mapp{$a ne 'undef' ? ($b,$a):()}@ary; foreach my $opt (sort{$a<=>$b} keys %hash) { print "$opt => $hash{$opt}\n"; } __END__ 2 => AirDefense 4 => Mobile-N-Site 6 => Owl