#!/usr/bin/perl -w use strict; use warnings; my @views = ( "ignore", "abbbbc", "mn123op", "ignore", "uvwxy", ); my %functions_hash = ( 'ab+c$' => [ 'b+', 'x' ], 'mn\d+' => [ '(\d+)', '' ], 'uvwxy' => [ 'uvw', 'UVW' ], ); foreach my $data (@views) { while (my ($key, $pvalue) = each %functions_hash) { if ($data =~ /$key/) { my ($from, $to) = ($pvalue->[0], $pvalue->[1]); $data =~ s/$from/$to/; print "data is now $data\n"; } } } #### data is now axc data is now mnop data is now UVWxy