The right answer is naturally to use one of the Getopt modules as the previous posters said. If you want to know a better way in detail, your algorithm is a good starting point, just change it slightly:
loop through @ARGV.
Check if the value starts with a "-"
if it does then figure out which flag it is and assign the correct variable with the next value in @ARGV. Step over both values
if the value doesn't start with a "-" and the previous value doesn't either, then take that as normal input and proceed with the script.
if the value doesn't start with a "-" but the previous value does, then treat it as the value for that flag
Instead of looping over the values you can shift them off the array, which makes the variable stepping much easier