#!/usr/bin/env perl use feature 'say'; use URL::Encode qw(:all); use String::ShellQuote; my %commands = ( encode => sub { say url_encode(shift) }, decode => sub { say url_decode(shift) }, ); die "Usage: $0 <${\join '|',keys %commands}> ARGS" unless @ARGV >= 1; my $command = shift; die "No such command $command" unless defined $commands{$command}; if (@ARGV) { for (@ARGV) { $commands{$command}->($_); } } else { while () { chomp; $commands{$command}->($_); } }