use strict; use warnings; use IO::File; foreach my $i (1 .. 30) { my $fh = IO::File->new("graph_set_$i.out") || die "Cannot open $i'th file\n"; # Use $fh here $fh->close; }