#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11109157 use warnings; my $line = 'A A Milne - Winnie-The-Pooh and Silver-Bear vol5-12 - Xi Press - Peking (1998)'; print "$line\n"; $line =~ s/-\K.*(?=-)/ $& =~ tr'-'_'r /e; print "$line\n"; #### A A Milne - Winnie-The-Pooh and Silver-Bear vol5-12 - Xi Press - Peking (1998) A A Milne - Winnie_The_Pooh and Silver_Bear vol5_12 _ Xi Press - Peking (1998)