foreach $old ( grep { -f $_ } @filez ) { $new = $old; next unless ( $new =~ s/$search/$replace/ ); # s/// returns false if there's no match if (( $force and $interactive ) or not $quiet ) { print "$old -> $new"; if ( $interactive ) { print " y/n? "; $yn = # no need for chomp here next unless ( $yn =~ /^y/i ); } else { print "\n" } } rename $old, $new if ( $force ); }