$name = ..... # whatever my $i= ''; --$i while (-e $name . $i); $name.= $i;