No doubt, this works. But it's doing a lot of work it doesn't need to.
- Copying the whole string around. You're matching the whole string, except for the terminating comma, and then copying it back into $query1.
- And then you're going to search the string again, presumably in case there is a second ending comma.
- And what is the 's' for? You may have a habit of using it, thinking it solves a lot of your problems. I think you might be cultivating a bad habit - perl probably does things as defaults that are good things, and you want to specify overriding behaviour only when you need it. (Minimalist theory.)
For the first one, just get rid of the (.*) and $1: $query1 =~ s#,$##gs. For the second, just add an appropriate plus sign: $query =~ s#,+$##s. For the last, well, just remove the ending s - it's not doing anything: $query =~ s#,+$##.
"Premature optimisation is the root of all evil." Well, I'm not optimising - I'm merely encouraging idiomatic use of perl: writing perl the way it should be. Minimally, but not unreadably. (The last part doesn't apply to obfu's and golf competitions.)
| [reply] [d/l] [select] |