my $title = "PowerBook_Duo_280"; my @result = split( "/", $title ); my $alttitle = ""; my $alttitle2 = ""; foreach (@result) { $alttitle = $_; $alttitle2 = $_; $alttitle =~ s/PowerBook_//g; $alttitle2 =~ s/PowerBook_/PB_/g; } print $alttitle . "\n"; print $alttitle2 . "\n"; # output: # jotham@leviathan:~$ perl replace.pl # Duo_280 # PB_Duo_280 # jotham@leviathan:~$