#!/usr/bin/perl use strict; use warnings; my $board = ('.' x 10 . "\n") x 10; print "$board\n"; my $input = '23hacross'; # simulated read from STDIN place($input); print "$board\n"; $input = '16vdown'; # simulated read from STDIN place($input); print "$board\n"; sub place { my $input = shift; my ($row, $column, $direction, $word) = $input =~ /^(\d)(\d)(v|h)(.*)/; my $position = 11 * $row + $column; for ( split //, $word ) { substr $board, $position, 1, $_; if( $direction eq 'h' ) { $position++; } else { $position += 11; } } }