#!/usr/bin/perl -w use strict; die "Usage: ", $0 =~ /([^\/]+)$/, " <[1|2|5|10|20|50]l | [5|10|20|50]p> [...]\n" unless @ARGV; my $sum; for (@ARGV){ die "$_ is an invalid amount/type of currency!\n" unless /^(5|[125]0(?=p)|[125]0?(?=l))([pl])$/i; $sum += $1 / ${{ p => 100, l => 1 }}{lc $2}; } print "The total is L$sum.\n";