my $file_name; if ( -e "1.txt"){ $file_name=$_; } elsif( -e "2.txt" ){ $file_name = $_; } if( $file_name ){ $fh = IO::File "<$file_name" or die $! }