#! /usr/bin/perl -l use strict; use warnings; { my @POOL = qw( A C G T ); sub mutate { my $str = shift; # original sequence my @positions = @_; # get all positions for mutations for my $pos ( @positions ) { # check each position my $original = substr $str, $pos-1, 1; # determine original my @replacer = grep { $_ ne $original } @POOL; # exclude original from replacement list substr( $str, $pos-1, 1) = $replacer[ rand @replacer ]; # replace original with a random item } # return mutated sequence return $str; } } my $sequence = "ACTA"; print mutate($sequence,3,4); # mutate at 3rd and 4th position of sequence