#!/usr/bin/perl -l # https://perlmonks.org/?node_id=1227618 use strict; use warnings; my $want = q{UK_Mobile_Vodafone_GBRVF}; my $dest = q{UK Mobile - Vodafone [GBRVF] [MSRN]}; print $dest; $dest =~ s/( )|- |\[|\].*/ '_' x !!$1 /ge; print $dest; print $want;