for (my $c = 1;; $c ++) { my $file = "graph_set_$c.out"; last unless -f $file; open my $fh => "<", $file or die "Failed to open $file: $!"; ... # Do something with $fh. }