use 5.020;
use strict;
use warnings;


say("Please enter the maximum possible multiple. ");
my $max = <STDIN>;


my @factors = ();
my $buffer;
say("Now enter the first factor and its associated word. Ex: 3 Fizz ");
chomp($buffer = <STDIN>);
push @factors, $buffer;
say("Now enter the second factor and its associated word. Ex: 5 Buzz ");
chomp($buffer = <STDIN>);
push @factors, $buffer;
say("Now enter the third factor and its associated word. Ex: 7 Baxx ");
chomp($buffer = <STDIN>);
push @factors, $buffer;


for(my $i = 1; $i <= $max; $i++)
{
    
    my $oBuffer;
    $buffer = $i;
    
    foreach my $element (@factors)
    {
        
        $element =~ /\s/;
        
        if($i % substr($element, 0, @-) == 0)
        {
            $oBuffer = $oBuffer . substr($element, @+ + 1, length($element));
            
            $buffer = "";
        }
    }
    
    if(length($buffer) > 0)
    {
        print($buffer . "\n");
    }
    else
    {
        print($oBuffer . "\n");
    }
}