in reply to get next higher number

But it doesn't quite work.

Doesn't quite work? It doesn't even compile.

$ perl -cw 1216404.pl syntax error at 1216404.pl line 2, near "my " 1216404.pl had compilation errors.

Even if it did compile how would you know if it works since it produces no output? See How to ask better questions using Test::More and sample data

Where is the problem and how to solve it?

Line 1 is missing a trailing semi-colon. Add one.

Is there a better solution?

Almost certainly but that would depend on in which way you would want them to be better.

I prefer not to use any other functions or modules.

If this is your definition of "better" then I will gladly leave you to it.

Can I do it some how with regex?

It would be very illuminating to hear your reasoning for asking this.