sub get_num{ my $dir = shift; my $c = 0; /(\d+)/ and $1>$c and $c=$1 while <$dir/foo_*.bar>; return $c+1; }