$filename =~ s[^.+/][]; # you have this one already $filename =~ tr/?&/_/; # just add this one (turns all ? and & into _)