sub munge { my $str = shift; $str =~ s/^R(?:([12])|(3))?$/(${1}||"")."text".($2||"")/e; $str; }