#!/usr/bin/perl -w use strict; my ($oldpat, $newpat); my ($oldname, $newname); $oldname = 'foo-64-bar'; # would normally be read from stdin # basic substitution $newname = $oldname; $newname =~ s/-([0-9]+)-/_$1_/; print "static patterns: $oldname becomes $newname\n"; # the same, but with the patterns in variables $oldpat = '-([0-9]+)-'; $newpat = '_$1_'; $newname = $oldname; $newname =~ s/$oldpat/$newpat/e; print "variable patterns: $oldname becomes $newname\n";