my $txtfile = $prefix . ".txt"; my $txtfile1 = $prefix . "1.txt"; if ( -f $txtfile ) { # do stuff } elsif ( -f $txtfile1 ) { # do stuff } else { # no file was found } #### if ( -f $txtfile || -f $txtfile1 ) { if ( -f $txtfile ) { open(FILE, "$txtfile"); } else { open(FILE, "$txtfile1"); } # do stuff with FILE close (FILE); } else { # no file was found }