while ($out !~ m/^[sSfF]{1}$/) { print ("Do you want to output to (S)creen or to (F)ile?\n"); chomp($out=); print("\nInvalid input.\n Please type either S or F.\n"); } if ($out =~ m/^[sS]{1}$/) { print $output; } elsif ($out =~ m/^[fF]{1}$/) { FILENAME: { while ($save !~ (m/^[a-zA-Z]{1}[a-zA-Z_0-9]*$/)) { print ("Please enter filename:\n"); chomp($save=); print("\nInvalid input.\n Please begin with a letter and do not add extension, it will be added automatically.\n"); } if (-e $save) { while ($overwrite !~ (m/^[nNyY]{1}$/)) { print("\nFilename exists. Overwrite? (Y) or (N)\n"); chomp($overwrite=); print("\nInvalid input.\n Please type either Y or N.\n"); } if ($overwrite =~ (m^/[nN]{1}$/)) { redo FILENAME; } else { open(DATA, ">$save")|| die "Couldn't open $path for writing: $!\n"; print DATA $output; close (DATA); } } } }