in reply to Strange Behaviour of Two Hashes

The error is on line 109: if ((my @gaps) = ($asstr =~ m/$regex/o)) The /o in your regex is telling Perl to compile the regular expression only once because the string $regex is never going to change. But it does change, because you call the subroutine more than once. Therefore, the regex gets compiled differently, depending on which call to the align() subroutine occurs first.

The way to fix it is to remove the /o from the regex: if ((my @gaps) = ($asstr =~ m/$regex/))