#!/usr/bin/perl -w use strict; use warnings; my %test = ( foo1 => 'a', foo2 => 'b', foo10 => 'c', ); my ($letzter) = sort {substr ($b,3) <=> substr ($a,3)} grep {$_ =~ /^foo\d+$/} (keys %test); print "$letzter\n";