in reply to Capture string that starts with #

Not addressing your problem but you could save some typing when testing your $command.

... if ( $command =~ m{^(?:set|add|del)$} ) { ...

I hope this is of interest.

Cheers,

JohnGG